寒假3.2

Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Examples
Input
WUBWUBABCWUB
Output
ABC
Input
WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB
Output
WE ARE THE CHAMPIONS MY FRIEND
Note
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
本題需要把wub去掉,定義兩個(gè)數(shù)組,如發(fā)現(xiàn)wub,則在另一數(shù)組中輸入空格,如不為wub,則直接復(fù)制到另一數(shù)組。

#include<iostream>
using namespace std;
int main()
{
    char a[201], b[201];
    cin >> a;
    int x, y = 0;
    for (x = 0; a[x] != 0; x++){}
    for (int i = 0; i < x; i++)
    {
        if (y == 0)
        {
            if (a[i] == 'W'&&a[i + 1] == 'U'&& a[i + 2] == 'B')
            {
                i += 2;
            }
            else
            {
                b[y] = a[i];
                y++;
            }
        }
        else
        {
            if (a[i] == 'W'&&a[i + 1] == 'U'&&a[i + 2] == 'B')
            {
                if (a[i + 3] == 'W'&&a[i + 4] == 'U'&&a[i + 5] == 'B')
                {
                    i += 2;
                }
                else
                {
                    b[y] = ' ';
                    y++;
                    i += 2;
                }

            }
            else
            {
                b[y] = a[i];
                y++;
            }
        }
    }
    if (b[y-1] != ' ')
    {
        for (int s = 0; s < y; s++)
        {
            cout << b[s];
        }
    }
    else
    {
        for (int s = 0; s < y-1; s++)
        {
            cout << b[s];
        }
    }
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 數(shù)組在程序設(shè)計(jì)中,為了處理方便, 把具有相同類型的若干變量按有序的形式組織起來(lái)。這些按序排列的同類數(shù)據(jù)元素的集合稱...
    朱森閱讀 4,270評(píng)論 2 13
  • 七、數(shù)組 在C語(yǔ)言中,數(shù)組屬于構(gòu)造數(shù)據(jù)類型。數(shù)組根據(jù)元素的類型不同,數(shù)組又可以分為 數(shù)值數(shù)組 、字符數(shù)組 、指針數(shù)...
    堅(jiān)持到底v2閱讀 901評(píng)論 0 2
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML標(biāo)準(zhǔn)。 注意:講述HT...
    kismetajun閱讀 28,816評(píng)論 1 45
  • 第5章 引用類型(返回首頁(yè)) 本章內(nèi)容 使用對(duì)象 創(chuàng)建并操作數(shù)組 理解基本的JavaScript類型 使用基本類型...
    大學(xué)一百閱讀 3,679評(píng)論 0 4
  • 醉酒 平臥孤自哀 綿綿愁緒來(lái) 放平杯中水 伴酒釋胸懷 冷風(fēng)吹酒醒 往事仿如夢(mèng) 四目擦肩過(guò) 憑空郁胸中 酒不解憂人自...
    怡馨宅閱讀 318評(píng)論 3 4

友情鏈接更多精彩內(nèi)容