codeforces #392 div2 B.Blown Garland

題目

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.

分析

我的理解就是4中顏色的燈妹沙,找一個(gè)符合他給的序列的循環(huán)格式墩剖,因?yàn)楸WC每個(gè)燈都出現(xiàn)一次界轩,所以直接遍歷一邊就可以找出4個(gè)燈的循環(huán)格式反症,然后遍歷第二遍去找!出現(xiàn)的地方應(yīng)該亮什么燈存捺,統(tǒng)計(jì)一下槐沼。

ac代碼

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>

using namespace std;
//const int maxs = 1e2 + 5;
char c[4] = {'R', 'B', 'Y', 'G'};
int num_col[4];
int ind[4];
string str;
int main(){
    cin >> str;
    int size = str.size();
    for(int i = 0; i < 4; ++i){
        for(int j = i; j < size; j += 4){
            if(str[j] == '!') {
                continue;
            }
            for(int k = 0; k < 4; ++k){
                if(str[j] == c[k]){
                    ind[i] = k;
                }
            }
        }
    }
    for(int i = 0; i < 4; ++i){
        for(int j = i; j < size; j += 4){
            if(str[j] == '!'){
                ++num_col[ind[i]];
            }   
        }
    }
    bool t_peace = 1;
    for(int i = 0; i < 4; ++i){
        if(t_peace){
            t_peace = 0;
        }
        else cout << " ";
        cout << num_col[i];
    }
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市捌治,隨后出現(xiàn)的幾起案子岗钩,更是在濱河造成了極大的恐慌,老刑警劉巖具滴,帶你破解...
    沈念sama閱讀 216,919評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件凹嘲,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡构韵,警方通過(guò)查閱死者的電腦和手機(jī)周蹭,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,567評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)疲恢,“玉大人凶朗,你說(shuō)我怎么就攤上這事∠匀” “怎么了棚愤?”我有些...
    開(kāi)封第一講書人閱讀 163,316評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)杂数。 經(jīng)常有香客問(wèn)我宛畦,道長(zhǎng),這世上最難降的妖魔是什么揍移? 我笑而不...
    開(kāi)封第一講書人閱讀 58,294評(píng)論 1 292
  • 正文 為了忘掉前任次和,我火速辦了婚禮,結(jié)果婚禮上那伐,老公的妹妹穿的比我還像新娘踏施。我一直安慰自己石蔗,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,318評(píng)論 6 390
  • 文/花漫 我一把揭開(kāi)白布畅形。 她就那樣靜靜地躺著养距,像睡著了一般。 火紅的嫁衣襯著肌膚如雪日熬。 梳的紋絲不亂的頭發(fā)上棍厌,一...
    開(kāi)封第一講書人閱讀 51,245評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音碍遍,去河邊找鬼定铜。 笑死阳液,一個(gè)胖子當(dāng)著我的面吹牛怕敬,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播帘皿,決...
    沈念sama閱讀 40,120評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼东跪,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了鹰溜?” 一聲冷哼從身側(cè)響起虽填,我...
    開(kāi)封第一講書人閱讀 38,964評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎曹动,沒(méi)想到半個(gè)月后斋日,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,376評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡墓陈,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,592評(píng)論 2 333
  • 正文 我和宋清朗相戀三年恶守,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片贡必。...
    茶點(diǎn)故事閱讀 39,764評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡兔港,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出仔拟,到底是詐尸還是另有隱情衫樊,我是刑警寧澤,帶...
    沈念sama閱讀 35,460評(píng)論 5 344
  • 正文 年R本政府宣布利花,位于F島的核電站科侈,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏炒事。R本人自食惡果不足惜臀栈,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,070評(píng)論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望羡洛。 院中可真熱鬧挂脑,春花似錦藕漱、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,697評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至刁俭,卻和暖如春橄仍,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背牍戚。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,846評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工侮繁, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人如孝。 一個(gè)月前我還...
    沈念sama閱讀 47,819評(píng)論 2 370
  • 正文 我出身青樓宪哩,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親第晰。 傳聞我的和親對(duì)象是個(gè)殘疾皇子锁孟,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,665評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,486評(píng)論 0 23
  • 永遠(yuǎn)不要嘲笑別人的夢(mèng)想。 忘了這句話是誰(shuí)說(shuō)的茁瘦,聽(tīng)過(guò)千萬(wàn)遍品抽,還是不理解、做不到——直到我遇到了一件小事甜熔。 我讀的是一...
    豬豬是程序猿閱讀 402評(píng)論 1 3
  • 我家有個(gè)脾氣特別的小表妹一一林曄曄圆恤。 林曄曄她特別愛(ài)哭:每天哭一次是家常便飯了,有時(shí)候還一天哭個(gè)五六...
    我愛(ài)hz閱讀 363評(píng)論 0 2
  • 在設(shè)計(jì)上我們應(yīng)該堅(jiān)持幾點(diǎn): ———不為1%的需求騷擾99%的用戶; ———淡淡的美術(shù)腔稀,點(diǎn)到即止; ———不能刻意地...
    熊孩子的帽紙閱讀 126評(píng)論 0 1
  • 目錄 上一話:屈家軍敗的原因由 下一話:穎果生日預(yù)祝 “天太乳業(yè)搞活動(dòng)買五送三盆昙,買一件送一件∩沼保” 這幾天弱左,樓下商店...
    牛8蒲哥閱讀 347評(píng)論 0 3