CodeForces 208A

A - WUB(*?-?*)WUB

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u

Submit Status Practice CodeForces
208A

Description

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 200characters. 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.

Sample Input

Input

WUBWUBABCWUB

Output

ABC 

Input

WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB

Output

WE ARE THE CHAMPIONS MY FRIEND 

Hint

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变成空格,如果在首不不输出空格,中间连续多个只算一个空格。

上代码

#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;
#include <string.h>
#include <stdlib.h>
int main()
{
	char s[2222];
	int i,j;
    while(scanf("%s",s)!=EOF)
	{
		int l=strlen(s);
		for(i=0;i<l;i++)
		{
			if(s[i]=='W' &&s[i+1]=='U'&&s[i+2]=='B')
			{
				s[i]=1;
				s[i+1]=1;
				s[i+2]=1;  //全变为一
			}
		}
		j=0;
		for(i=0;i<l;i++)
		{

			if(j==1)
			{
				if(s[i]==1 && s[i+1]==1&& s[i+2]==1)
				{
					printf(" ");
					j=0;  //保证连续的空格只输出一个。
				}
			}
            if(s[i]!=1) //不等于1才输出
			{
				printf("%c",s[i]);
				j=1;  //只有先输出首字母 上面的J==1才有输出空格的权利
			}
		}
		printf("\n");
	}
	return 0;
}
时间: 2024-10-05 15:35:29

CodeForces 208A的相关文章

python 学习笔记(一)通过做题来熟悉python 的基本语法

codeforces 208-A 将原字符串中的"WUB"子串去掉 s = input() a = s.split('WUB') for t in a: if t!='': print(t,end=' ') 1. input input进来的是string,如果要读一个数字的话,要用int()转为数字 int( input() ) 2. a = s.split(str) 将原串 按str进行分割,然后存到的到子串存到一个集合当中 eg: s ="a$b$c"  a

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Codeforces Round #408 (Div. 2) B

Description Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x?=?i. The probl

Codeforces 617 E. XOR and Favorite Number

题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j)}$表示区间${\left [ l,r \right ]}$内数字的异或和. 那么:${f(l,r)=f(1,r)~~xor~~f(1,l-1)=k}$ 记一下前缀异或和即可维护. 1 #include<iostream> 2 #include<cstdio> 3 #include&l