Blown Garland CodeForces

来源:互联网 发布:java软件设计大赛 编辑:程序博客网 时间:2024/06/05 14:24

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.

Example
Input
RYBGRYBGR
Output
0 0 0 0
Input
!RGYB
Output
0 1 0 0
Input
!!!!YGRB
Output
1 1 1 1
Input
!GB!RG!Y!
Output
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.

题意:GBRG代表各种灯泡的颜色,!表示坏了的灯泡,他们维持这一定的顺序,4种不同颜色的为一组,要求列出的灯泡顺序中,每组不能出现相同的颜色。

分析:思路要清晰。直接看代码吧

先来一遍遍历,记住每种颜色的所占的位置蜀(0~3)碰到"!"也要除以4取余,得他应该是处于什么位置,亮什么颜色的灯,得出n[i]代表颜色的个数。思路很重要,一定要思路清晰。

#include <cstdio>#include <algorithm>#include <iostream>#include <queue>#include <string.h>using namespace std;char a[105];int n[5];int main(){    int len,r,b,g,y;    int i;    gets(a);    len=strlen(a);    for(i=0; i<len; i++)    {        if(a[i]=='R')        {            r=i%4;        }        else if(a[i]=='B')        {            b=i%4;        }        else if(a[i]=='Y')        {            y=i%4;        }        else if(a[i]=='G')        {            g=i%4;        }        else        {            n[i%4]++;        }    }    printf("%d %d %d %d\n",n[r],n[b],n[y],n[g]);    return 0;}


原创粉丝点击