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);
}

Polycarp and Letters(set首战!)的更多相关文章

  1. Codeforce B. Polycarp and Letters

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

  2. [Codeforces 864B]Polycarp and Letters

    Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...

  3. Codeforces Round #436 (Div. 2) B. Polycarp and Letters

    http://codeforces.com/contest/864/problem/B 题意: 给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字 ...

  4. Codeforces Round #436 B. Polycarp and Letters

    题意:给你一串长度为n的字符,由大小写字母组成,求连续的小写子串中不同字母个数的最大值. Input 11aaaaBaabAbA Output 2 Input 12zACaAbbaazzC Outpu ...

  5. CF Round#436 div2

    额,这次的题目其实挺智障的.所以通过这次比赛,我也发现了自己是一个智障.... 不说太多,说多是泪... A. Fair Game 题意:给你一个数组,看你能否把它均分为两个所有元素均相同的子数组. ...

  6. Codeforces Round #436 (Div. 2) A,B,D

    A. Fair Game 题目链接:http://codeforces.com/contest/864/problem/A 水题 #include<iostream> #include&l ...

  7. Codeforces Round #436 (Div. 2)【A、B、C、D、E】

    Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...

  8. Codeforces Round #436 (Div. 2) 题解864A 864B 864C 864D 864E 864F

    A. Fair Game time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. codefoeces 864B

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

随机推荐

  1. 【2016 ICPC亚洲区域赛北京站 E】What a Ridiculous Election(BFS预处理)

    Description In country Light Tower, a presidential election is going on. There are two candidates,   ...

  2. PHP程序员学Objective-C之后的变化

    趣味坎谈,不一定100%准确,以自己的实际情况为准; 如题,我2008年开始学PHP,PHP是我学的第二门编程语言,一直用到现在,2010年初开始做iOS开发,学习了Objective-C,学这2门语 ...

  3. Phaser3 对象池随机产生炸弹并销毁

    效果图 对象池 Object Pool scene.js /// <reference path="../../libs/phaser/phaser.min.js"/> ...

  4. 百度云虚拟主机BCH安装PHP框架CodeIgniter

    百度云虚拟主机BCH官方未支持CodeIgniter框架,本人参加php中文网活动获取一百度云虚拟主机,本人选的ThinkPHP版,但本人喜欢CodeIgniter框架,因此尝试在该主机上配置Code ...

  5. Delphi 调试连接 任意Android手机/平板/盒子

    Delphi有时候无法连接调试一些手机,解决方案: 1.安装Google USB Driver 2.通过设备管理器查看手机或平板USB的VID,PID 3.修改你的电脑上的android_winusb ...

  6. PE 学习之路 —— DOS 头、NT 头

    1. 前述 可执行文件的格式是操作系统本身执行机制的反映,理解它有助于对操作系统的深刻理解,掌握可执行文件的数据结构及其一些机理,是研究软件安全的必修课.`PE(Portable Executable ...

  7. 大数据学习--day17(Map--HashMap--TreeMap、红黑树)

    Map--HashMap--TreeMap--红黑树 Map:三种遍历方式 HashMap:拉链法.用哈希函数计算出int值. 用桶的思想去存储元素.桶里的元素用链表串起来,之后长了的话转红黑树. T ...

  8. python 运算符与分支结构

    运算符与分支结构 运算符 赋值运算符 用'='表示,左边只能是变量 算术运算符 +.-.*:加.减.乘 /:除法运算,结果是浮点型 //:除法运算,结果是整型 %:求余 **:求幂 复合运算符 +=. ...

  9. C语言数据结构与算法之深度、广度优先搜索

    一.深度优先搜索(Depth-First-Search 简称:DFS) 1.1 遍历过程: (1)从图中某个顶点v出发,访问v. (2)找出刚才第一个被顶点访问的邻接点.访问该顶点.以这个顶点为新的顶 ...

  10. PMP考试总结

    9月8日参加完PMP考试,从上第一次课7月14日到考试,历经56天.5次面授课,3次模考,对整个项目管理有了清晰的认识和学习.感觉上课是一回事,做题又是一回事,考试又是另外一回事.考试一共4个小时,从 ...