输入:abcc 输出:3
输入:baddabce 输出: 4
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
string str;
getline(cin, str);
int count = 0;
int max = 0;
vector<char> vec;
for (int i = 0; i < str.size(); ++i) {
//在vec中搜索当前字符
int j;
for (j = 0; j < vec.size(); ++j) {
if (vec[j] == str[i])
break;
}
if (j == vec.size())//表示当前字符没有出现在vec中
vec.push_back(str[i]);
else {
vec.clear();
vec.push_back(str[i]);
}
count = vec.size();
if (count > max)
max = count;
}
cout << max << endl;
system("pause");
}