寒假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去掉,定义两个数组,如发现wub,则在另一数组中输入空格,如不为wub,则直接复制到另一数组。

#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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 数组在程序设计中,为了处理方便, 把具有相同类型的若干变量按有序的形式组织起来。这些按序排列的同类数据元素的集合称...
    朱森阅读 4,024评论 2 13
  • 七、数组 在C语言中,数组属于构造数据类型。数组根据元素的类型不同,数组又可以分为 数值数组 、字符数组 、指针数...
    坚持到底v2阅读 855评论 0 2
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,802评论 1 45
  • 第5章 引用类型(返回首页) 本章内容 使用对象 创建并操作数组 理解基本的JavaScript类型 使用基本类型...
    大学一百阅读 3,272评论 0 4
  • 醉酒 平卧孤自哀 绵绵愁绪来 放平杯中水 伴酒释胸怀 冷风吹酒醒 往事仿如梦 四目擦肩过 凭空郁胸中 酒不解忧人自...
    怡馨宅阅读 263评论 3 4