【 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?in the string are all distinct and lowercase;
- 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 aaaaBaabAbAOutput
2Input
12 zACaAbbaazzCOutput
3Input
3 ABCOutput
0Note
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.
?
題目大意:
? ?就是說給一個(gè)字符串問你有多少 在不被大寫字母分割的子串中(也就是不含大寫字母的子串中),小寫字母的種類數(shù)最多? 有多少個(gè)。
解題報(bào)告:
? ? 反正數(shù)據(jù)量很小,,隨便寫就行。
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 ;}總結(jié):
? ?注意最后輸出的時(shí)候也需要取max,因?yàn)槿f一沒進(jìn)那個(gè)if(cnt[s[i]] == 0)這個(gè)if的話,,比如輸入:x? ? 那就涼涼啊。所以小地方一定要注意,,,還有一種處理辦法就是每個(gè)tmp++之后就ans更新一下。。。還是那句話 一定要小范圍測試一下!!
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的【 CodeForces - 864B】Polycarp and Letters(水题,字符串,有坑)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【HDU - 1847】Good Luc
- 下一篇: 非法集资有哪些常见的套路?什么是非法集资