B. Polycarp and Letters
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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.

Examples
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<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<sstream>
#include<algorithm>
#include<string>
#include <cstring>
using namespace std;
const int maxn = 111;
int nu[maxn];
set<int> st;
string s;
int main() {
ios::sync_with_stdio(false);
int n;
int maxx = 0;
cin>>n>>s;
s+="A";
for(int i = 0; i <= n; i++) {
// cout<<st.size()<<endl;
if(s[i] >= 'a' && s[i] <= 'z') st.insert(s[i]);
else maxx = max(maxx,(int)st.size()),st.clear();
}
cout<<maxx<<endl;
return 0; }

  

codefoeces 864B的更多相关文章

  1. Codefoeces 734F. Anton and School 数学

    Codefoeces 734F 题目大意: 给定两个正整数序列\(b,c\)构造一个正整数序列\(a\)使其满足 \[ \left\{ \begin{array}{} b_i=(a_i\text{ a ...

  2. CodeFoeces 1215 D Ticket Game(数学,思维)

    CodeFoeces 1215 D Ticket Game 题目大意 M和B轮流玩游戏(每一轮M先手 现在给出一个长度为偶数的串,包含字符'?'和数字 现在两人依次在'?'上填数字\(0\)~\(9\ ...

  3. [Codeforces 864B]Polycarp and Letters

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

  4. codefoeces problem 671D——贪心+启发式合并+平衡树

    D. Roads in Yusland Mayor of Yusland just won the lottery and decided to spent money on something go ...

  5. codefoeces 671 problem D

    D. Roads in Yusland standard output Mayor of Yusland just won the lottery and decided to spent money ...

  6. 刷题总结——book of evil(codefoeces 337D)

    题目: description Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This ar ...

  7. codefoeces B. Friends and Presents

    B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...

  8. CodeFoeces GYM 101466A Gaby And Addition (字典树)

    gym 101466A Gaby And Addition 题目分析 题意: 给出n个数,找任意两个数 “相加”,求这个结果的最大值和最小值,注意此处的加法为不进位加法. 思路: 由于给出的数最多有 ...

  9. 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 ...

随机推荐

  1. 如何在 crontab 中让 source ~/.bashrc 生效

    cron 是许多类 Unix 操作系统中都自带的用来调度定时任务的工具,定时任务的配置是写在 crontab 文件中的,但是 crontab 文件不允许直接编辑,一般都是通过命令 crontab -e ...

  2. uni-app开发经验分享七: 有关列表数据下拉加载方法的解析及记录

    在使用uni.request获取后台数据时,我们往往碰到一个问题,列表的懒加载及数据实时更新,这里记录下我制作这类功能的方法. 问题描述:后台返回数据,前端需要进行10个为一组来分页,先显示前10个, ...

  3. LVS负载均衡IP隧道模式原理介绍以及配置实战

    LVS 基本工作原理 当用户向负载均衡调度器(Director Server)发起请求,调度器将请求发往至内核空间 PREROUTING 链首先会接收到用户请求,判断目标 IP 确定是本机 IP,将数 ...

  4. C++ Primer Plus读书笔记(二)处理数据

    1.格式化输出: 和C语言不太一样,C++格式化输出进制格式如下: 1 int a = 42; 2 int b = 42; 3 int c = 42; 4 5 cout << a < ...

  5. libevent之基于socket的bufferevent

    基于socket的bufferevent由一个socket的传输层和read/write buffer组成.区别于常规的event,当socket可读或者可写时会回调用户的callback,buffe ...

  6. libevent源码学习之event

    timer event libevent添加一个间隔1s持续触发的定时器如下: struct event_base *base = event_base_new(); struct event *ti ...

  7. 最短路-Bellmm-ford算法

    Bellmm-ford算法 解决什么样的问题 有边数限制的最短路,存在负权边,负环 概念 通俗的来讲就是:假设 1 号点到 n 号点是可达的,每一个点同时向指向的方向出发,更新相邻的点的最短距离,通过 ...

  8. Java面试(解答题一)

    1.简述下列问题 List,set,map的区别 解答:List,Set都是继承自Collection接口,Map则不是: List特点:元素有放入顺序,元素可重复 ,Set特点:元素无放入顺序,元素 ...

  9. Jenkins (自动使用docker容器发布java.war +tomcat)

    一.大概流程 因为目前没有找Jenkins 和docker 之间比较友好的插件,所以只能使用这种比较low 的方式来实现自动部署了. 1.Jenkins在gitlab拉取项目并编译. 2.将编译后的代 ...

  10. WebApi Swagger 接口多版本控制 适用于APP接口管理

    最近研究了下swagger多版本的维护,网上的文章千篇一律,无法满足我的需求,分享下我的使用场景以及实现 演示环境:Visual Studio 2019.Asp.NET WebAPI.NET Fram ...