2020.10.23-vj个人赛补题
B - B
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
11
aaaaBaabAbA
2
12
zACaAbbaazzC
3
3
ABC
0
Note
In the first example the desired positions might be 6 and 8or 7 and 8. Positions 6 and 7 contain letters 'a', position 8contains 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.
题意:求连续的小写字母中不同字母的最大数量
题解:运用set,set可以去掉重复的字母,存到一个字符串数组里,同时记录下长度,找到最长的输出
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[1000];
int n,ct=0;
set<char>b;
cin>>n>>s;
for(int i=0;i<n;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
b.insert(s[i]);
}
else{
if(ct<b.size())ct=b.size();
b.clear();
}
}
if(ct<b.size)ct=b.size();
b.clear();
cout<<ct<<endl;
}
E - E
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.
Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.
It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.
Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.
Input
The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:
- 'R' — the light bulb is red,
- 'B' — the light bulb is blue,
- 'Y' — the light bulb is yellow,
- 'G' — the light bulb is green,
- '!' — the light bulb is dead.
The string s can not contain other symbols except those five which were described.
It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.
It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.
Output
In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.
Examples
RYBGRYBGR
0 0 0 0
!RGYB
0 1 0 0
!!!!YGRB
1 1 1 1
!GB!RG!Y!
2 1 1 0
Note
In the first example there are no dead light bulbs.
In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.
题解:每四个一循环,同时记录下每种缺少的字母的个数,我是特判了字符串长度为4的时候,看是否有不存在的字母,若有则直接设为一,长度大于4时,每四个一循环对比看缺少的是哪个,同时另为“!”的值等于相应的字母,继续重复对比循环
#include<bits/stdc++.h>
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
string s,k;
int r=0,b=0,y=0,g=0;
cin>>s;
int m,i,j;
m=s.size();
if(m==4)
{
for(i=0;i<4;i++)
{
if(s[i]=='R')r++;
else if(s[i]=='B')b++;
else if(s[i]=='Y')y++;
else if(s[i]=='G')g++;
}
if(r==0)r=1;else r=0;
if(b==0)b=1;else b=0;
if(y==0)y=1;else y=0;
if(g==0)g=1;else g=0; cout<<r<<" "<<b<<" "<<y<<" "<<g<<endl;
}
else{
for(i=0;i<m;i++)
{
if(i+4<m)
{
if(s[i]=='!')
{
for(j=i+4;j<m;j+=4)
{
if(s[j]!='!')
{
if(s[j]=='R')s[i]='R',r++;
else if(s[j]=='B')s[i]='B',b++;
else if(s[j]=='Y')s[i]='Y',y++;
else if(s[j]=='G')s[i]='G',g++;
break;
}
}
}
}
if(i-4>=0)
{
if(s[i]=='!')
{
for(j=i-4;j>=0;j-=4)
{
if(s[j]!='!')
{
if(s[j]=='R')s[i]='R',r++;
else if(s[j]=='B')s[i]='B',b++;
else if(s[j]=='Y')s[i]='Y',y++;
else if(s[j]=='G')s[i]='G',g++;
break;
}
}
}
}
}
cout<<r<<" "<<b<<" "<<y<<" "<<g<<endl;
}
}
2020.10.23-vj个人赛补题的更多相关文章
- 2020.10.17-pta天梯练习赛补题
7-5敲笨钟 微博上有个自称"大笨钟V"的家伙,每天敲钟催促码农们爱惜身体早点睡觉.为了增加敲钟的趣味性,还会糟改几句古诗词.其糟改的方法为:去网上搜寻压"ong&quo ...
- 2020.11.1--pta阶梯练习赛补题
7-5 古风排版 中国的古人写文字,是从右向左竖向排版的.本题就请你编写程序,把一段文字按古风排版. 输入格式: 输入在第一行给出一个正整数N(<),是每一列的字符数.第二行给出一个长度不超过1 ...
- 2020.10.30--vj个人赛补题
D - D CodeForces - 743A Vladik is a competitive programmer. This year he is going to win the Interna ...
- 2020.10.16--vj个人赛补题
D - Drinks Choosing Old timers of Summer Informatics School can remember previous camps in which eac ...
- 2020.10.9--vj个人赛补题
B - A Tide of Riverscape 题意:给出一组字符串,由'0','1',' . '组成,' . '可以换成 0或1,判断第 i 个和第 i+p 个字符是否可以不相等,如果可以则输出 ...
- QFNU-ACM 2020.04.05个人赛补题
A.CodeForces-124A (简单数学题) #include<cstdio> #include<algorithm> #include<iostream> ...
- 2020.12.3--vj个人赛补题
A Vasya studies music.He has learned lots of interesting stuff. For example, he knows that there are ...
- 2020.12.20-Codeforces Round #105补题
B - Escape The princess is going to escape the dragon's cave, and she needs to plan it carefully. Th ...
- 2020.11.14-pta天梯练习赛补题
7-7 矩阵A乘以B 给定两个矩阵A和B,要求你计算它们的乘积矩阵AB.需要注意的是,只有规模匹配的矩阵才可以相乘.即若A有Ra行.Ca列,B有Rb行.Cb列,则只有Ca ...
随机推荐
- 三大操作系统对比使用之·Windows10
时间:2018-10-29 记录:byzqy 本篇是一篇个人对Windows系统使用习惯.技巧和应用推荐的文档,在此记录.分享和后续查询备忘. 打开终端: Win+R,调出"运行" ...
- 1.3w字,一文详解死锁!
死锁(Dead Lock)指的是两个或两个以上的运算单元(进程.线程或协程),都在等待对方停止执行,以取得系统资源,但是没有一方提前退出,就称为死锁. 1.死锁演示 死锁的形成分为两个方面,一个是使用 ...
- Blazor 组件库开发指南
翻译自 Waqas Anwar 2021年5月21日的文章 <A Developer's Guide To Blazor Component Libraries> [1] Blazor 的 ...
- Linux制作根文件系统笔记
测试平台 宿主机平台:Ubuntu 12.04.4 LTS 目标机:Easy-ARM IMX283 目标机内核:Linux 2.6.35.3 交叉编译器:arm-linux-gcc 4.4.4 Bus ...
- Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
背景 有一个 Flask 项目,然后有一个路由返回的是 dict 通过浏览器访问,结果报错 关键报错信息 TypeError: 'dict' object is not callable The vi ...
- AQS学习(二) AQS互斥模式与ReenterLock可重入锁原理解析
1. MyAQS介绍 在这个系列博客中,我们会参考着jdk的AbstractQueuedLongSynchronizer,从零开始自己动手实现一个AQS(MyAQS).通过模仿,自己造轮子来学习 ...
- ysoserial CommonsColletions3分析(1)
CC3的利用链在JDK8u71版本以后是无法使用的,具体还是由于AnnotationInvocationHandler的readobject进行了改写. 而CC3目前有两条主流的利用链,利用Trans ...
- 跨域分布式系统单点登录的实现(CAS单点登录)
1. 概述 上一次我们聊了一下<使用Redis实现分布式会话>,原理就是使用 客户端Cookie + Redis 的方式来验证用户是否登录. 如果分布式系统中,只是对Tomcat做了负载均 ...
- nmap使用命令(转载)原文地址https://www.jianshu.com/p/4030c99fcaee
- 第一节:《线程安全和锁Synchronized概念》
第一节:线程安全和锁Synchronized概念 一.进程与线程的概念 (1)在传统的操作系统中,程序并不能独立运行,作为资源分配和独立运行的基本单位都是进程. 在未配置 OS 的系统中,程序的执行方 ...