codefoeces 864B
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.
这道题一直理解不了题意,看了代码才知道到底啥意思。
就是先找出每一段小写字母里的不同元素有多少个,再输出其中最大那一段的值。
#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的更多相关文章
- Codefoeces 734F. Anton and School 数学
Codefoeces 734F 题目大意: 给定两个正整数序列\(b,c\)构造一个正整数序列\(a\)使其满足 \[ \left\{ \begin{array}{} b_i=(a_i\text{ a ...
- CodeFoeces 1215 D Ticket Game(数学,思维)
CodeFoeces 1215 D Ticket Game 题目大意 M和B轮流玩游戏(每一轮M先手 现在给出一个长度为偶数的串,包含字符'?'和数字 现在两人依次在'?'上填数字\(0\)~\(9\ ...
- [Codeforces 864B]Polycarp and Letters
Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...
- codefoeces problem 671D——贪心+启发式合并+平衡树
D. Roads in Yusland Mayor of Yusland just won the lottery and decided to spent money on something go ...
- codefoeces 671 problem D
D. Roads in Yusland standard output Mayor of Yusland just won the lottery and decided to spent money ...
- 刷题总结——book of evil(codefoeces 337D)
题目: description Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This ar ...
- codefoeces B. Friends and Presents
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CodeFoeces GYM 101466A Gaby And Addition (字典树)
gym 101466A Gaby And Addition 题目分析 题意: 给出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 ...
随机推荐
- 基于HBuilderX+UniApp+ColorUi+UniCloud 优宝库 开发实战(一)
1. 优宝库介绍 优宝库是基于阿里妈妈.淘宝联盟 淘宝商品Api,前端使用HBuilderX + UniApp + ColorUi,后端采用UniClound 精选淘宝商品进行推荐的App程序.下 ...
- JS中常用的工具类
一.日期工具类 /** * 日期时间工具类 * @type {{dateFormat}} */ var DateTime = function () { var patterns = { PATTER ...
- 解决安装mysql动态库libstdc++.so.6、libc.so.6版本过低问题
初始化mysql报错: ./bin/mysqld: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ...
- 风险识别系统-大数据智能风控管理平台-企业风控解决方案– 阿里云 https://www.aliyun.com/product/saf
风险识别系统-大数据智能风控管理平台-企业风控解决方案– 阿里云 https://www.aliyun.com/product/saf
- Django Admin后台添加用户时出现报错:1452
如果在使用Django Admin后台添加用户时出现报错: (1452, 'Cannot add or update a child row: a foreign key constraint fai ...
- Jaspersoft Studio报表设计
1 开发工具 1.1 软件名称 名称:TIBCO Jaspersoft Studio 版本:6.0或以上,建议6.2.1 1.2 软件安装 免安装软件包,拷贝即可使用,建议放在D:盘或其 ...
- web.xml 监听器
一.作用 Listener就是在application,session,request三个对象创建.销毁或者往其中添加修改删除属性时自动执行代码的功能组件. Listener是Servlet的监听器, ...
- Display属性学习总结
HTMl元素根据表现形式,常见的可以分为两类. (1)块元素(block) (2)行内元素(inline). 当然,除了以上两种元素类型外,还有inline-block.table-cell等元素类型 ...
- 笔趣看小说Python3爬虫抓取
笔趣看小说Python3爬虫抓取 获取HTML信息 解析HTML信息 整合代码 获取HTML信息 # -*- coding:UTF-8 -*- import requests if __name__ ...
- HTML之form表单标签的学习
from表单 表示 <form>form表单域</form> 作用 收集并替提交用户数据给指定服务器 属性 action:收集的数据的提交地址(也就是URL) method:收 ...