2018美團筆試字串問題

2022-05-26 12:48:18 字數 2137 閱讀 6308

輸出對應的答案。

in:aab

abaout:2

in:aaabb

babout:5

題解:

(n)

'>o(n

)o(n)

。#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

#define

is_lower(c

) (c >='a'&&c

<='z'

)#define

is_upper(c

) (c >='a'&&c

<='z'

)#define

is_alpha(c

) (is_lower

(c) ||is_upper

(c))

#define

is_digit(c

) (c >='0'&&c

<='9'

)#define

min(

a, b

) ((a)

<(b) ?(a) :(b))

#define

max(

a, b

) ((a) >(b) ?(a) :(b))

#define

piacos

(-1)

#defineio\

ios::sync_with_stdio(0

); \

cin.

tie(

0);

\cout.

tie(0);

#define

for(

i, a, b

) for

(int i =a; i

<=b; i++)

typedef

long

long ll;

typedef

unsigned

long

long ull;

typedef pair pii;

typedef pairpll;

typedef vector vi;

const ll inf = 0x3f3f3f3f;

const

double eps = 1e-10;

const ll inf_ll = (ll)1e18;

const ll maxn = 100005ll;

const ll mod = 1000000007ll;

const

int n = 10000+5;

/*題目:

給出兩個相同長度的由字元 a 和 b

構成的字串,定義它們的距離為對應位置不同的字元的數量。如串」aab」與串」aba」的距離為

2;串」ba」與串」aa」的距離為 1;串」baa」和串」baa」的距離為 0。下面給出兩個字串 s 與

t,其中 s 的長度不小於 t 的長度。我們用|s|代表 s 的長度,|t|代表 t

的長度,那麼在 s 中一共有|s|-|t|+1 個與t長度相同的子串,現在你需要計算 t

串與這些|s|-|t|+1 個子串的距離的和。

輸入描述:

第一行包含乙個字串 s。第二行包含乙個字串 t。s 和 t 均由字元 a 和 b 組成,1 ≤

|t| ≤ |s| ≤105 。

輸出描述:

輸出對應的答案。

樣例:in:

aababa

out:

2in:

aaabb

babout:

5*/char s[n],t[n];

intmain()

cout << ans << endl;

}

字串距離 2023年美團程式設計題

題目描述 給出兩個相同的由字元a和b構成的字串,定義它們的距離為對應位置不同的字元的數量。如串 aab 與串 aba 的距離是2 串 ba 與串 aa 的距離是1 串 aba 與串 aba 的距離是0。下面給出兩個字串s和t,其中s的長度不小於t的長度。我們用 s 表示s的長度,用 t 表示t的長度...

美團CODEM 字串

時間限制 1秒 空間限制 32768k 給出乙個正整數n,我們把1.n在k進製下的表示連起來記為s n,k 例如s 16,16 123456789abcdef10,s 5,2 11011100101。現在對於給定的n和字串t,我們想知道是否存在乙個k 2 k 16 使得t是s n,k 的子串。輸入描...

美團2020筆試 字串逆排序

題目描述 將以逗號分隔的輸入字串按z a的順序排序,空字元位於最前面,當乙個字串是另乙個字串的子串時,排在前面。import sys import operator def resort arr n len arr count 0 for i in range n if arr i arr i ar...