zoukankan      html  css  js  c++  java
  • B. Blown Garland

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
     

    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就可以找出来连续的四种颜色,之所以挂出来是因为第一次学会了用字符表示数组地址。

    附AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 char a[110];
     5 int c[110];
     6 
     7 int main(){
     8 //    ios::sync_with_stdio(false);
     9     ios::sync_with_stdio(false);
    10     string s;
    11     cin>>s;
    12     int r,y,b,g;
    13     int len=s.size();
    14     for(int i=0;i<len;i++){
    15         if(s[i]!='!'){
    16             a[i%4]=s[i];
    17         }
    18     }
    19     for(int i=0;i<len;i++){
    20         if(s[i]=='!'){
    21             c[a[i%4]]++;
    22         }
    23     }
    24     cout<<c['R']<<" "<<c['B']<<" "<<c['Y']<<" "<<c['G']<<endl;
    25     return 0;
    26 } 
  • 相关阅读:
    关于<?php exit;?>"的绕过问题
    机器学习--DIY笔记与感悟--②决策树(1)
    机器学习--DIY笔记与感悟--①K-临近算法(2)
    js 一些基础的理解
    js switch判断 三目运算 while 及 属性操作
    数据类型 数据类型转换 运算符
    数组的一些常用方法分析 介绍
    js常用的字符串方法分析
    js 的作用域 域解析 分析
    js 函数 作用域 全局作用域 局部作用域 闭包
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/6321987.html
Copyright © 2011-2022 走看看