• 10.22补题


    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

    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.

    解题思路:先每4个遍历一遍找出每种颜色的灯泡出现的次数,然后总数对4取余看是否有多余颜色计入,最后总数减去出现次数及取余数。

    ac代码:

    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<map>
    #include<cstring>
    using namespace std;
    int main(){
        char s[105],a[105];
        int m,i,b[105]={0};
        cin>>s;
        m=strlen(s);
        for(i=0;i<m;i+=4){
             if(s[i]!='!'){
                 a[0]=s[i];
                b[0]++;
             }
        }
        for(i=1;i<m;i+=4){
             if(s[i]!='!'){
                 a[1]=s[i];
                b[1]++;
             }
        }
        for(i=2;i<m;i+=4){
             if(s[i]!='!'){
                 a[2]=s[i];
                b[2]++;
             }
        }
        for(i=3;i<m;i+=4){
             if(s[i]!='!'){
                 a[3]=s[i];
                b[3]++;
             }
        }
        for(i=0;i<=3;i++){
            if(a[i]=='R'){
                cout<<m/4+(m%4>=(i+1)?1:0)-b[i]<<" ";
            }
        }
        for(i=0;i<=3;i++){
            if(a[i]=='B'){
                cout<<m/4+(m%4>=(i+1)?1:0)-b[i]<<" ";
            }
        }
        for(i=0;i<=3;i++){
            if(a[i]=='Y'){
                cout<<m/4+(m%4>=(i+1)?1:0)-b[i]<<" ";
            }
        }
        for(i=0;i<=3;i++){
            if(a[i]=='G'){
                cout<<m/4+(m%4>=(i+1)?1:0)-b[i]<<endl;
            }
        }
        return 0;
    } 
    View Code
  • 相关阅读:
    HDU 1698 Just a Hook(线段树区间替换)
    NBOJv2 1034 Salary Inequity(DFS序+线段树区间更新区间(最值)查询)
    NBOJv2 1004 蛤玮打扫教室(线段树区间更新区间最值查询)
    NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)
    POJ 3468 A Simple Problem with Integers(线段树区间更新区间查询)
    HDU 1754 I Hate It(线段树单点更新区间最值查询)
    HDU 1166敌兵布阵+NOJv2 1025: Hkhv love spent money(线段树单点更新区间查询)
    GDUT——1169: Krito的讨伐(优先队列BFS)
    HDU——2444The Accomodation of Students(BFS判二分图+最大匹配裸题)
    HDU——1045Fire Net(最大匹配)
  • 原文地址:https://www.cnblogs.com/nanan/p/13911069.html
Copyright © 2020-2023  润新知