codeforces-758b Blown Garland

Source: Internet
Author: User

The IT eternal in the world, Kostya understood it on the 7-th of January as he saw partially dead four-color garland .

Now it has a goal to replace dead light bulbs, however his doesn ' t know how many light the for each color bulbs are. It is guaranteed this for each of four colors in least one light is working.

It is known the Garland contains light bulbs of four colors:red, blue, yellow and green. The Garland is made as follows:if your take any four consecutive light bulbs then there won't be light bulbs with the s Ame color among them. For example, the Garland can look like "rybgrybgry", "YBGRYBGRYBG", "Bgryb", but can don't look like "Bgryg", "Ybgrybygr" or "Bgybgy". Letters denote colors: ' R '-red, ' B '-blue, ' Y '-yellow, ' G '-green.

Using the information that to each color at least one light bulb still works count the number of dead light bulbs of each Four colors. Input

The "the" and "Only" line contains the string s (4≤|s|≤100), which describes the Garland, the i-th symbol of which D Escribes the color of the i-th light bulb in the order from the beginning of Garland: ' R '-the light bulb is red, ' B '-t He light bulb are blue, ' Y '-the light bulb is yellow, ' G '-the light are green, '! ' bulb-the light is bulb.

The string s can not contain other symbols except those five which were.

It is guaranteed this given string at least once there be each of four letters ' R ', ' B ', ' Y ' and ' G '.

It is guaranteed the string S. Correct garland with some blown light bulbs, it means this for example the line GRB Y!!! B "Can not is 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 example there are no dead light bulbs.

In the second example it is obvious this one blue bulb is blown, because it could not being light bulbs of other colors on it s place according to the statements.
Go through it to find out how many times each bulb appears, and then use the total to subtract the number of occurrences that you need to add.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> char s[105];

using namespace Std;
    int main () {char c[5];
    int cnt[5];
    memset (CNT, 0, sizeof (CNT));
    scanf ("%s", s); for (int i = 0; I < strlen (s); i = 4) {if (S[i]!= '! ')
    {C[0] = S[i]; cnt[0]++} for (int i = 1; i < strlen (s); i = 4) {if (S[i]!= '! ')
    {C[1] = S[i]; cnt[1]++} for (int i = 2; I < strlen (s); i = 4) {if (S[i]!= '! ')
    {c[2] = S[i]; cnt[2]++} for (int i = 3; I < strlen (s); i = 4) {if (S[i]!= '! ')
    {C[3] = S[i]; cnt[3]++} for (int i = 0; I <= 3; i++) {if (c[i] = = ' R ') printf ("%d", strlen (s)/4 + (strlen (s)% 4 >= (i + 1)?
    1:0)-cnt[i]); for (int i = 0; I <= 3; i++) {if (c[i] = = ' B ') printf ("%d", strlen (s)/4 + (strlen (s)% 4 >= (i + 1)?
    1:0)-cnt[i]); for (int i = 0; I &Lt;= 3;
    i++) {if (c[i] = = ' Y ') printf ("%d", strlen (s)/4 + (strlen (s)% 4 >= (i + 1)? 1:0)-cnt[i]);  for (int i = 0; I <= 3; i++) {if (c[i] = = ' G ') printf ("%d", strlen (s)/4 + (strlen (s)% 4 >= (i + 1)?
    1:0)-cnt[i]);

return 0;
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.