【 CodeForces - 864B】Polycarp and Letters(水题,字符串,有坑)

版权声明:欢迎学习我的博客,希望ACM的发展越来越好~ https://blog.csdn.net/qq_41289920/article/details/83904161

题干:

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
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更新一下。。。还是那句话 一定要小范围测试一下!!

猜你喜欢

转载自blog.csdn.net/qq_41289920/article/details/83904161