CF 208A Dubstep(简单字符串处理)
题目链接: 传送门
Dubstep
Time Limit: 1000MS Memory Limit: 32768 KB
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 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.
Sample Input
WUBWUBABCWUB
WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB
Sample Output
ABC
WE ARE THE CHAMPIONS MY FRIEND
思路:
简单字符串处理,删除"WUB"输出剩下的字符。
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
string str,tmp;
cin >> str;
int len = str.size();
for (int i = 0;i < len;)
{
string s = str.substr(i,3);
if (s == "WUB")
{
i += 3;
}
else
{
tmp += str[i];
i++;
string s = str.substr(i,3);
if (s == "WUB")
{
tmp += ' ';
}
}
}
if (tmp != "")
cout << tmp << endl;
return 0;
}
CF 208A Dubstep(简单字符串处理)的更多相关文章
- 第一部分之简单字符串SDS(第二章)
一,什么是SDS? 1.引出SDSC字符串:c语言中,用空字符结尾的字符数组表示字符串简单动态字符串(SDS):Redis中,用SDS来表示字符串.在Redis中,包含字符串值的键值对在底层都是由SD ...
- hdu 5059 简单字符串处理
http://acm.hdu.edu.cn/showproblem.php?pid=5059 确定输入的数是否在(a,b)内 简单字符串处理 #include <cstdio> #incl ...
- C 封装一个通用链表 和 一个简单字符串开发库
引言 这里需要分享的是一个 简单字符串库和 链表的基库,代码也许用到特定技巧.有时候回想一下, 如果我读书的时候有人告诉我这些关于C开发的积淀, 那么会走的多直啊.刚参加工作的时候做桌面开发, 服务是 ...
- 1442: Neo 的简单字符串(字符串)
1442: Neo 的简单字符串 时间限制: 10 Sec 内存限制: 128 MB 提交: 9 解决: 3 统计 题目描述 Neo 给你一系列字符串,请你输出字符串中的不同单词个数以及总单词个数. ...
- Codeforces 208A:Dubstep(字符串)
题目链接:http://codeforces.com/problemset/problem/208/A 题意 给出一个字符串,将字符串中的WUB给删去,如果两个字母间有WUB,则这两个字母用空格隔开 ...
- Java实验--关于简单字符串回文的递归判断实验
首先题目要求写的是递归的实验,一开始没注意要求,写了非递归的方法.浪费了一些时间,所谓吃一堑长一智.我学习到了以后看实验的时候要认真看实验中的要求,防止再看错. 以下是对此次的实验进行的分析: 1)递 ...
- python 简单字符串字典加密
1 def crypt(source,key): from itertools import cycle result='' temp=cycle(key) for ch in source: res ...
- 洛谷 简单字符串 'P1055ISBN号码' 问题
题目描述如下: 知识点①:char数组与int型数字进行运算时,需要将 char[i]-'0' .比如 char c[5]; int i; for(i=0;i<5;i++) scanf(&quo ...
- c# 进程间的通信实现之一简单字符串收发
使用Windows API实现两个进程间(含窗体)的通信在Windows下的两个进程之间通信通常有多种实现方式,在.NET中,有如命名管道.消息队列.共享内存等实现方式,这篇文章要讲的是使用Wi ...
随机推荐
- Spring 依赖注入方式详解
平常的Java开发中,程序员在某个类中需要依赖其它类的方法. 通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖类不由 ...
- 单片机C语言探究--为什么变量最好要赋初值
有许多书上说,变量最好要赋初值.但是为什么要初值呢?不赋初值可能会出现什么样的意外呢?以下就我在以51单片机为MCU,Keil为编译器看到的实现现象作分析.众所周知,变量是存储在RAM中,掉电后即丢失 ...
- SQL基础之数据库快照
1.认识快照 如名字一样,数据库快照就可以理解为数据库某一时刻的照片,它记录了此时数据库的数据信息.如果要认识快照的本质,那就要了解快照的工作原理.当我们执行t-sql创建快照后,此时就会创建一个或多 ...
- jquery图片轮播效果(unslider)
今天做网站(住建局网站)需要用到图片轮播,刚开始想借鉴DTCMS上的,查看CSS与页面代码,呵呵,不复杂,直接复制过来,结果调整半天,页面还是各种乱,没办法,网上找一个吧,于是找到了今天要说的这货un ...
- snr ber Eb/N0之间的区别与联系
信噪比(S/N)是指传输信号的平均功率与加性噪声的平均功率之比,载噪比(C/N)指已经调制的信号的平均功率与加性噪声的平均功率之比,它们都以对数的方式来计算,单位为dB. 对同一个传输系统而言,载噪比 ...
- word2vec 实践
关于word2vec,这方面无论中英文的参考资料相当的多,英文方面既可以看官方推荐的论文,也可以看gensim作者Radim Řehůřek博士写得一些文章.而中文方面,推荐 @licstar的< ...
- htop查看系统负载
htop 是 Linux 系统中的一个互动进程查看器,可以让用户进行交互式操作,可横向或纵向滚动浏览进程列表,支持鼠标操作.用户可以在安装 htop 来监控服务器的负载. 01.下载 https:// ...
- 【Python】[函数式编程]高阶函数,返回函数,装饰器,偏函数
函数式编程高阶函数 就是把函数作为参数的函数,这种抽象的编程方式就是函数式编程.--- - -跳过,不是很理解,汗 - ---
- [AJAX系列]XMLHttpRequest请求
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HTML5+AJAX原生分块上传文件的关键参数设置
processData:false 这是jquery.ajax的一个参数.默认值为true,表示会将非字符串对象自动变成k1=v1&k2=v2的形式,例如一个数组参数{d:[1,2]},到服务 ...