求字串中滿足所有字元個數相等的最長子串長度

2021-06-26 09:52:18 字數 487 閱讀 7471

乙個字串,只包含a,b,c三種字母,比如aabbbcbcaaa,找出乙個最長子串,要求包含的三種字母個數相同,返回最長子串的長度即可。比如串aabbbcbcaaa的最長子串是bcbcaa,包含a,b,c都是2個。

實現下面c++函式:

下面是一種o(n)的實現方法。

int getmaxlen(string& src)

#include #include #include #include using namespace std;

int getmaxlen(string& src)

else

} map< vector, vector>::iterator bianli=j.begin();

int max=0;

while(bianli!=j.end())

bianli++;

} return max;

}int main()

求合法字串個數

合法字串個數 題目描述 給定數字n,輸入n個字串。規定合法的字串需要滿足 1.字串首位為大寫英文本元 2.除了首位之外的字元均為小寫英文本元。例如xiaotuzi是乙個合法的字串,而xiaotuzi不是合法的字串 請輸出一共有多少個合法字串 輸入描述 輸入共n 1行 第一行包括乙個整數n n 10 ...

c 中字串相等

string a hello 宣告乙個string 變數 string b a 將a賦予b,實際是將a的引用給b string c h c ello console.writeline object a object b 判斷引用是否相等 console.writeline object a obj...

求字串中漢字的個數

一 分解字串法 首先建立這個函式 將字串分解 create function dbo splitchar str one nvarchar 100 returns result table col nvarchar 1 as begin declare number one int select n...