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.

此题求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的更多相关文章

  1. [Codeforces 864B]Polycarp and Letters

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

  2. Polycarp and Letters(set首战!)

    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. Android 屏幕刷新机制

    这次就来梳理一下 Android 的屏幕刷新机制,把我这段时间因为研究动画而梳理出来的一些关于屏幕刷新方面的知识点分享出来,能力有限,有错的地方还望指点一下.另外,内容有点多,毕竟要讲清楚不容易,所以 ...

  2. 【Java数据结构学习笔记之一】线性表的存储结构及其代码实现

    应用程序后在那个的数据大致有四种基本的逻辑结构: 集合:数据元素之间只有"同属于一个集合"的关系 线性结构:数据元素之间存在一个对一个的关系 树形结构:数据元素之间存在一个对多个关 ...

  3. Codeforces Round #300(Div. 2)-538A.str.substr 538B.不会 538C.不会 。。。

    A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Spring框架学习笔记(10)——Spring中的事务管理

    什么是事务 举例:A给B转500,两个动作,A的账户少500,B的账户多500 事务就是一系列的动作, 它们被当做一个单独的工作单元. 这些动作要么全部完成, 要么全部不起作用 一.注解添加事务管理方 ...

  5. lombok使用基础教程

    前言 lombok是一个编译级别的插件,它可以在项目编译的时候生成一些代码.在很多工具类的项目中都有这个功能.比如dagger. 通俗的说,lombok可以通过注解来标示生成getter settte ...

  6. MongoDB模拟多文档事务操作

    Mongodb不支持多文档原子性操作,因此依据两阶段提交协议(Two Phase Commits protocol)来模拟事务. 以两个银行账户之间的转账行为为例,来说明如何实现多文档间的事务操作. ...

  7. 使用npm install报错-4048 operation not permitted解决

    刚刚使用npm install时一直报错-4048 operation not permitted,也尝试了多种方法,终于使问题得到解决,这里总结几种方法,先贴图: 一:权限问题 首先看到operat ...

  8. [国嵌攻略][069][Bootm命令移植]

    Bootloader作用 1.初始化软硬件 2.启动操作系统 内核分类 1.zImage 不加信息头的内核 2.uImage 加信息头后的内核,用bootm命令来启动 bootm作用 1.检测信息头: ...

  9. [国嵌攻略][044][初始化Bss段]

    BSS段的作用 1.变量存储的空间 初始化的全局变量:数据段 未初始化的全局变量:BSS段 局部变量:栈 动态分配变量:堆 2.为什么要对BSS段初始化 未初始化的全局变量在使用时才被赋值,未了避免在 ...

  10. for语句,你真正搞懂了吗?

    今天看书时,无意间看到了这个知识点,啥知识点?也许在各位大神看来,那是再简单不过的东西了. 说来惭愧.原来直到今天我才真正搞懂for语句. for语句的结构如下所示: for(语句A;语句B;语句C) ...