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. redis 安装 配置 及启动

    linux下安装redis及其中遇到的问题的解决方法1.将下载好的压缩包放到/usr/local目录下# tar xzf redis-3.0.2.tar.gz# cd redis-3.0.2# mak ...

  2. 【学时总结】 ◆学时·III◆ 二分图

    [学时·III] 二分图 ■基本策略■ 其实本质是图论中的网络流 二分图是两个由多个点组成的集合(上部和下部,且没有重叠),两个集合中的点不与该集合内其他的点连通,但和另一个集合内的点连通.我们称这两 ...

  3. swiper在vue中正确的使用方法

    1.安装swiper,执行npm install vue-awesome-swiper --save命令 2.在main.js中添加下面三行 import 'swiper/dist/css/swipe ...

  4. Hadoop HA 高可用集群搭建

    一.首先配置集群信息 vi /etc/hosts 二.安装zookeeper 1.解压至/usr/hadoop/下 .tar.gz -C /usr/hadoop/ 2.进入/usr/hadoop/zo ...

  5. SQL宽字节注入

    0x00 概述 - 什么是宽字节注入? 宽字节注入就是因为gbk编码方式需要两个ascii码组合来解码,所以形象的叫做宽字节,这个作为了解即可 -宽字节注入的条件 1) 数据库查询设置为GBK编码 2 ...

  6. ubuntu 和windows 分别在anaconda上安装tensorflow

    windows下 的anaconda安装tensorflow: 在Anaconda Prompt中:conda install tensorflow python=3.5一直下载失败.总结一下原因可能 ...

  7. 20155308 2016-2017-2 《Java程序设计》实验二 Java面向对象程序设计

    20155308 2016-2017-2 <Java程序设计>实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UM ...

  8. 对Linux命令od -tc -tx1的C语言程序实现myod-优化版

    导语 自编od C语言实现版名为myod 上个星期有一个初代版,链接- myod原版 这星期的课上要求实现myod-系统调用版本,要求如下 1 参考教材第十章内容 2 用Linux IO相关系统调用编 ...

  9. Java技术——Interface与abstract类的区别

    )抽象类是对类抽象,是面向整个类的自下而上的设计理念,一般是先有各种子类,再有把这些有关系的子类加以抽象为父类的需求.而接口是对行为的抽象,是面向行为的自上而下的设计理念,接口根本就不需要知道子类的存 ...

  10. Spring MVC接受参数的注解

    一.Request请求发出后,Headler Method是如何接收处理数据的? Headler Method绑定常用的参数注解,根据处理request的不同部分分为四类: A.处理 Request ...