B. Polycarp and Letters

B. Polycarp and Letters
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting 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 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 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.

其实只要看懂题了,就挺简单的.但是貌似我一开始是想多的.

只要每次碰到大写字母判断下就行,别忘记最后再来个特判.

 1 #include <bits/stdc++.h>
 2 #define N 205
 3 #define mem(a) memset(a,0,sizeof(a))
 4 using namespace std;
 5 int n;
 6 string s;
 7 bool a[26];
 8 int main(){
 9     cin>>n;
10     cin>>s;
11     int len =s.length();
12     int ma=0;
13     for(int i=0;i<len;i++){
14         if(s[i]<='z'&&s[i]>='a')
15             a[s[i]-'a']=1;
16         else{
17 
18             int ans=0;
19             for(int i=0;i<26;i++){
20               ans+=a[i];
21             }
22             mem(a);
23             ma=max(ma,ans);
24         }
25     }
26     int p=0;
27     for(int i=0;i<26;i++)
28       p+=a[i];
29       ma=max(ma,p);
30     cout<<ma<<endl;
31   return 0;
32 }
原文地址:https://www.cnblogs.com/zllwxm123/p/7596974.html