【 CodeForces - 864B】Polycarp and Letters(水題,字串,有坑)
題幹:
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string sconsisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met:
- letters on positions from A
- there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a1 < j < a2 for some a1 and a2 from A
Write a program that will determine the maximum number of elements in a pretty set of positions.
Input
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
Output
Print maximum number of elements in pretty set of positions for string s.
Examples
Input
11 aaaaBaabAbA
Output
2
Input
12 zACaAbbaazzC
Output
3
Input
3 ABC
Output
0
Note
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0.
題目大意:
就是說給一個字串問你有多少 在不被大寫字母分割的子串中(也就是不含大寫字母的子串中),小寫字母的種類數最多 有多少個。
解題報告:
反正資料量很小,,隨便寫就行。
AC程式碼:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int bk[MAX];
int cnt[505];
int n,tmp;
char s[505];
int main()
{
cin>>n;
cin>>s+1;
int len = strlen(s+1),ans = 0,tmp=0;
for(int i = 1; i<=len; i++) {
if(isupper(s[i])) {
memset(cnt,0,sizeof cnt);
ans = max(ans,tmp);
tmp=0;
continue;
}
if(cnt[s[i]] == 0) {
tmp++;
cnt[s[i]]++;
}
}
printf("%d\n",max(tmp,ans));
return 0 ;
}
總結:
注意最後輸出的時候也需要取max,因為萬一沒進那個if(cnt[s[i]] == 0)這個if的話,,比如輸入:x 那就涼涼啊。所以小地方一定要注意,,,還有一種處理辦法就是每個tmp++之後就ans更新一下。。。還是那句話 一定要小範圍測試一下!!