Blown Garland
来源:互联网 发布:淘宝买发票 搜索什么 编辑:程序博客网 时间:2024/05/19 14:53
Blown Garland
DESCRIPTION
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.
思路:每一段四个字符所在相对位置必须相同,比如abcdabcd,如果abcdbacd的话 肯定会有一个区间有重复,这里就是bcdb两个b重复了,所以相对位置必须相同,即每个字符%4都相同
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;char s[105];int main(){ while(scanf("%s",s)!=EOF) { int n=strlen(s),a[4]={0},b[4]={0},c[4]={0}; for(int i=0;i<n;i++) { c[i%4]++; if(s[i]=='R') { a[0]=i%4; b[0]++; } if(s[i]=='B') { a[1]=i%4; b[1]++; } if(s[i]=='Y') { a[2]=i%4; b[2]++; } if(s[i]=='G') { a[3]=i%4; b[3]++; } } for(int i=0;i<4;i++) printf("%d ",c[a[i]]-b[i]); cout<<endl; } return 0;}
0 0
- Blown Garland
- Codeforces758B Blown Garland
- 【Codeforces 758 Blown Garland】
- B. Blown Garland
- Blown Garland CodeForces
- 【codeforces 758B】Blown Garland
- Codeforces #392 B. Blown Garland
- Codeforces 758B-Blown Garland
- CodeForces 758B Blown Garland
- CF758 B. Blown Garland (模拟)
- 颜色不同的灯-Blown Garland
- Codeforces Round #392 (Div. 2)Blown Garland
- cf 758 B. Blown Garland模拟
- CF-Codeforces Round #392 (Div. 2)-B-Blown Garland
- Codeforces Round #392 (Div. 2) B - Blown Garland
- Codeforces Round #392 (Div. 2)-B. Blown Garland(水题)
- Codeforces Round #392(Div. 2) B Blown Garland【暴力枚举】
- Codeforces Round #392 (Div. 2)B Blown Garland
- 尚软科技-参与第十一届开源中国开源世界高峰论坛成功召开
- SQL判断某列中是否包含中文字符或者英文字符
- centos 为OPENJDK配置JAVA_HOME环境变量,安装MAVEN
- 深入理解Lock的底层实现原理
- RESTful架构风格概述
- Blown Garland
- 1 ~ 9 章
- Android-自定义圆角Dialog遇到的问题
- MYSQL服务启动、停止和重启
- POJ1321
- linux下面如何将文件编码批量转化
- GridLayout(网状布局)的使用
- poj 1733 Parity game(离散化+带权并查集+二分查找)
- 二维数组的鞍点