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
11
aaaaBaabAbA
2
12
zACaAbbaazzC
3
3
ABC
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首战!)的更多相关文章
- Codeforce B. Polycarp and Letters
B. Polycarp and Letters time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- [Codeforces 864B]Polycarp and Letters
Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...
- Codeforces Round #436 (Div. 2) B. Polycarp and Letters
http://codeforces.com/contest/864/problem/B 题意: 给出一个字符串,要求找到一个集合S,使得从S中选出的所有数,在这些数的位置上的字母全部为小写且是不同的字 ...
- Codeforces Round #436 B. Polycarp and Letters
题意:给你一串长度为n的字符,由大小写字母组成,求连续的小写子串中不同字母个数的最大值. Input 11aaaaBaabAbA Output 2 Input 12zACaAbbaazzC Outpu ...
- CF Round#436 div2
额,这次的题目其实挺智障的.所以通过这次比赛,我也发现了自己是一个智障.... 不说太多,说多是泪... A. Fair Game 题意:给你一个数组,看你能否把它均分为两个所有元素均相同的子数组. ...
- Codeforces Round #436 (Div. 2) A,B,D
A. Fair Game 题目链接:http://codeforces.com/contest/864/problem/A 水题 #include<iostream> #include&l ...
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
- 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 ...
- codefoeces 864B
B. Polycarp and Letters time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- Angular7教程-02-Angular项目目录及基本文件说明
本教程基于Angular7,更新时间2018-11-05. 1. 项目根目录如下: e2e文件夹:end to end,测试目录,主要用于集成测试. node_modules:项目的模块依赖目录. s ...
- mysql/mariadb学习记录——连接查询(JOIN)
//本文使用的数据表格//persons表中id_p为主键//orders表中id_o为主键,id_p为外键参考persons表中的id_p mysql> select * from perso ...
- swiper插件几个容易忽略的地方
以下内容为swiper4版本的 1.在我们用swiper插件做轮播的当我们左右滑动后会出现自动轮播停止了 此时我们需要在autoplay中 加上这个属性 autoplay:{ delay:1000, ...
- 浏览器内多个标签页之间的通信之storage
在一个标签页里面使用 localStorage.setItem(key,value)添加(修改.删除)内容: 在另一个标签页里面监听 storage 事件. 即可得到 localstorge 存储的值 ...
- 在Titanic数据集上应用AdaBoost元算法
一.AdaBoost 元算法的基本原理 AdaBoost是adaptive boosting的缩写,就是自适应boosting.元算法是对于其他算法进行组合的一种方式. 而boosting是在从原始数 ...
- 20155206 《Java程序设计》实验三实验报告
20155206 <Java程序设计>实验三实验报告 实验内容 Java敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验步骤 提交一: 提交二: 提交三: 提交四:
- C语言字节对齐问题详解(对齐、字节序、网络序等)
首先说明一下,本文是转载自: http://www.cnblogs.com/clover-toeic/p/3853132.html 博客园用的少,不知道怎么发布转载文章,只能暂时这样了. 引言 考虑下 ...
- 20155213 2016-2017-2 《Java程序设计》第十周学习总结
20155213 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 掌握Java Socket编程 理解混合密码系统 掌握Java 密码技术相关API的使用 网 ...
- WPF中。。DataGrid 实现时间控件和下拉框控件
DatePicker 和新的 DataGrid 行 用户与 DataGrid 中日期列的交互给我造成了很大的麻烦. 我通过将一个 Data Source 对象拖动到 WPF 窗口上,创建了一个 Dat ...
- Pomelo.AspNetCore.TimedJob 允许依赖注入
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStar ...