Polycarp and Letters(set首战!)

Description

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.

Sample Input

Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0

Hint

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.

题目意思:求连续的小写子母中,种类最多的是多少种。

解题思路:利用set中存储的元素的唯一 性去重,第一次使用set,还是对set中的删除不是很熟悉,当时使用set的迭代器也就是一个个删除的

for(it=st.begin(); it!=st.end();)
{
st.erase(it++);
}

实际上set中含有直接清空容器的函数clear().

 #include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
char s[];
int main()
{
int n,i,sum,sum1;
char a;
sum=;
sum1=;
scanf("%d",&n);
getchar();
scanf("%s",s);
set<char>st;
set<char>::iterator it;
for(i=; i<n; i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
sum1=st.size();
/*for(it=st.begin(); it!=st.end();)
{
st.erase(it++);
}*/
st.clear();
if(sum1>sum)
{
sum=sum1;
}
}
else if(s[i]>='a'&&s[i]<='z')
{
st.insert(s[i]);
}
}
sum1=st.size();
if(sum1>sum)
{
sum=sum1;
}
printf("%d\n",sum);
}
上一篇:CSS自学笔记(11):CSS3背景和边框


下一篇:e798. 显示JSlider的标记标签