当前位置:网站首页>770. 单词替换
770. 单词替换
2022-07-28 20:50:00 【Hunter_Kevin】
题目
输入一个字符串,以回车结束(字符串长度不超过 100)。
该字符串由若干个单词组成,单词之间用一个空格隔开,所有单词区分大小写。
现需要将其中的某个单词替换成另一个单词,并输出替换之后的字符串。
输入格式
输入共 3 行。
第 1 行是包含多个单词的字符串 s;
第 2 行是待替换的单词 a(长度不超过 100);
第 3 行是 a 将被替换的单词 b(长度不超过 100)。
输出格式
共一行,输出将 s 中所有单词 a 替换成 b 之后的字符串。
输入样例:
You want someone to help you
You
I
输出样例:
I want someone to help you
代码
#include <iostream>
#include <sstream> //需要用到的stringstream头文件
using namespace std;
int main()
{
string s, a, b;
getline(cin, s);
cin >> a >> b;
stringstream ssin(s);//把字符串转成字符串流,之后ssin类似于cin,区别是ssin可以从指定的字符串流s中读取字符串
string tmp;//存储临时从字符串流s中读取的字符串
while(ssin >> tmp)//一直从字符串流s中读取字符串到tmp中
if(tmp == a) cout << b << ' ';//如果tmp == a,则输出b
else cout << tmp << ' ';//否则输出原串
return 0;
}
边栏推荐
- Netease Yunxin 2022q2 product supply station, come and get your product supply plan!
- Sword finger offer II 054. Sum of all values greater than or equal to nodes (medium binary search tree DFS)
- HCIP(10)
- 20-09-27项目迁移到阿里折腾记录(网卡顺序导致服务无法通过haproxy连接到db)
- DOM programming + events
- 20-09-27 the project is migrated to Alibaba toss record (the network card order makes the service unable to connect to DB through haproxy)
- SQL注入 Less34(POST型宽字节注入+布尔盲注)
- SQL injection less34 (post wide byte injection + Boolean blind injection)
- What are the main functions and uses of LCR tester
- Can the MySQL create statement be used to create a table structure and append new records
猜你喜欢

想要快速成长,先要经历重大打击!

Win11怎么打开软件通知
Integrating database Ecology: using eventbridge to build CDC applications

微信小程序剪切图片的功能

How to install WiFi correctly

(翻译)图技术简明历史

How about the actual use effect of common source oscilloscope

6K6w5LiA5qyh5pS75Ye75YiG5p6Q

SQL injection less34 (post wide byte injection + Boolean blind injection)

6K6w5LiA5qyh5pS75Ye75YiG5p6Q
随机推荐
ssh 免密码登录
Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing
There will be a black line on the border when the button in the wechat applet is clicked
静态路由和缺省路由实验
gprs网络指的是什么
Static details of static members
Use webworker to perform background tasks
Sword finger offer II 064. magic Dictionary (medium dictionary tree string design)
LCR测试仪最为主要的功能和用途都是什么
Alibaba cloud CDN practice
PaddleNLP基于ERNIR3.0文本分类:WOS数据集为例(层次分类)
SQL injection less38 (Stack Injection)
Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)
LeetCode刷题系列之-多数之和类型
JS array merging, de duplication, dimensionality reduction (es6: extended operator, set)
Changes in the history of oscilloscope development
SSH password free login
redis相关
[CS231N]Lecture_ 2:Image Classification pipelin
Wechat applet uses canvas drawing, round avatar, network background, text, dotted line, straight line