博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 864B - Polycarp and Letters
阅读量:5138 次
发布时间:2019-06-13

本文共 1991 字,大约阅读时间需要 6 分钟。

 Polycarp and Letters

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.
Example
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
Note
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.

题意:找小写字母的子串中最多的不重复的字母个数。
#include
#include
#include
#include
#include
#include
using namespace std;map
m;int main(){ int n; while(~scanf("%d",&n)) { m.clear(); string s; cin>>s; int ans=0,anss=0; for(int i=0; i
='A'&&s[i]<='Z') { m.clear(); anss=max(anss,ans); ans=0; continue; } else if(s[i]>='a'&&s[i]<='z') { if(m[s[i]]==0) { ans++; anss=max(anss,ans); m[s[i]]=1; } } } cout<
<

转载于:https://www.cnblogs.com/da-mei/p/9053329.html

你可能感兴趣的文章
Python IO模型
查看>>
DataGridView的行的字体颜色变化
查看>>
局域网内手机访问电脑网站注意几点
查看>>
[Serializable]的应用--注册码的生成,加密和验证
查看>>
Android-多线程AsyncTask
查看>>
LeetCode【709. 转换成小写字母】
查看>>
如果没有按照正常的先装iis后装.net的顺序,可以使用此命令重新注册一下:
查看>>
【题解】青蛙的约会
查看>>
autopep8
查看>>
Android 官方新手指导教程
查看>>
幸运转盘v1.0 【附视频】我的Android原创处女作,请支持!
查看>>
安装 Express
查看>>
存储(硬件方面的一些基本术语)
查看>>
Weka中数据挖掘与机器学习系列之基本概念(三)
查看>>
leetcode-Sort List
查看>>
中文词频统计
查看>>
Java泛型的基本使用
查看>>
bzoj2038 [2009国家集训队]小Z的袜子(hose)
查看>>
Postman-----如何导入和导出
查看>>
移动设备显示尺寸大全 CSS3媒体查询
查看>>