Codeforce B. Polycarp and Letters
2 seconds
256 megabytes
standard input
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.
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.
Print maximum number of elements in pretty set of positions for string s.
11
aaaaBaabAbA
2
12
zACaAbbaazzC
3
3
ABC
0
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.
此题求2个大写字母间小写字母不同的个数;
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; int n,m,a[],maxx,ans;
char s[]; int main(){
scanf("%d",&n);
scanf("%s",s);
maxx=; ans=;
for(int i=;i<n;i++){
if(s[i]>='A'&&s[i]<='Z'){
memset(a,,sizeof(a));
ans=max(ans,maxx);
maxx=;
}else{
if(!a[s[i]]){
a[s[i]]=;
maxx++;
}
}
}
ans=max(maxx,ans);
printf("%d",ans);
}
Codeforce B. Polycarp and Letters的更多相关文章
- [Codeforces 864B]Polycarp and Letters
Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...
- Polycarp and Letters(set首战!)
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 ...
随机推荐
- Java与算法之(9) - 直接插入排序
直接插入排序是最简单的排序算法,也比较符合人的思维习惯.想像一下玩扑克牌抓牌的过程.第一张抓到5,放在手里:第二张抓到3,习惯性的会把它放在5的前面:第三张抓到7,放在5的后面:第四张抓到4,那么我们 ...
- HDU4920-Matrix multiplication-矩阵乘法 51nod-1137 矩阵乘法
先贴两个基础的矩阵乘法,以后再贴一些题. hdu. Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Lim ...
- CodeForces-2015 HIAST Collegiate Programming Contest-Gym-100952A-Who is the winner?
A. Who is the winner? time limit per test 1 second memory limit per test 64 megabytes input standard ...
- 2017广东工业大学程序设竞赛E题(倒水)
Description 一天,CC买了N个容量可以认为是无限大的瓶子,开始时每个瓶子里有1升水.接着~~CC发现瓶子实在太多了,于是他决定保留不超过K个瓶子.每次他选择两个当前含水量相同的瓶子,把一个 ...
- SSH私用私钥登陆
1.导入私钥,将私钥文件放到当前登陆用户目录下的.ssh目录下 2.指定私钥登陆,ssh -i .ssh/ssh_rsa root@target.com 如果出现了下面这种情况 这是因为私钥文件权限 ...
- SQL强化(二) 在Oracle 中写代码
一 : 关于查询中的转换 -- 字符串转换 一 : decode 函数 转换 SELECT DECODE ( PROTYPE.PRO_TYPE_DATE, 'L', '长', 'm', '短', ' ...
- 工作小结(关于webpack)
今天在工作中遇到了一个新问题,是关于webpack的. 是这样的,我在项目中添加了一个新页面,修改完配置文件后,开始运行,刚开始并没有什么问题,很顺利,后来我又添加了一个页面,然后修改配置文件,然后运 ...
- JavaScript八张思维导图—字符串用法
JS基本概念 JS操作符 JS基本语句 JS数组用法 Date用法 JS字符串用法 JS编程风格 JS编程实践 不知不觉做前端已经五年多了,无论是从最初的jQuery还是现在火热的Angular,Vu ...
- Tomcat软件使用常见问题
Tomcat软件使用常见问题 tomcat软件使用的常见问题 1)闪退问题 原因:tomcat软件是java语言开发的. tomcat软件启动时,会默认到系统的环境变量中查找一个名称叫JAVA_HOM ...
- 一致性哈希java实现
值得注意的点 哈希函数的选择 murmur哈希函数 该函数是非加密型哈希,性能高,且发生哈希碰撞的概率据说很低 md5 SHA 可以选择guava包,提供了丰富的哈希函数的API 支持虚拟节点+加权, ...