题解 CF864B 【Polycarp and Letters】
STL大法好哦!
本题我采用的是unordered_map+string+暴力(n <= 200,限时2s暴力挺快的,不会TLE的)
那怎么做呢?
首先,我们读入一个字符串,用我们双重循环,枚举自区间,注意每次map都要clear,每次读取map的size并和maxn(max好像定义过,再定义成变量会CE(编译失败))做比较
代码如下,706ms:
#include <iostream>
#include <cstring>
#include <unordered_map>
using namespace std;
int n, maxn = 0;
string s;
unordered_map <char, int> mp;
int main()
{
cin >> n >> s;
int x = s.length() - 1;
for(int i = 0; i <= x; i++)
{
mp.clear();
for(int j = i; j <= x; j++)
{
if(s[j] >= 'A' && s[j] <= 'Z')
{
break;
}
mp[s[j]] = 1;
}
int c = mp.size();
if(c > maxn)
{
maxn = c;
}
}
cout << maxn << endl;
return 0;
}

浙公网安备 33010602011771号