当前位置:网站首页>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;
}
边栏推荐
- LVS+KeepAlived高可用部署实战应用
- 【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
- Win11怎么打开软件通知
- LCR测试仪最为主要的功能和用途都是什么
- SQL injection less42 (post stack injection)
- What are the main functions and uses of LCR tester
- Establishment of Ruiji takeout development environment
- 6K6w5LiA5qyh5pS75Ye75YiG5p6Q
- SSH password free login
- Day3 classification management of Ruiji takeout project
猜你喜欢

Less than a year after its establishment! MIT derivative quantum computing company completed financing of US $9million

Soft exam network engineer

Idea generate class diagram plug-in UML (super detailed)

软考网络工程师

HCIP(8)

Which is the file transfer command in the basic services of the Internet

If you want to grow rapidly, you must first experience a major blow!

Static route and default route experiment

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

2022年一级建造师考试什么时候才能报名?
随机推荐
AWK空行过滤
SQL injection less34 (post wide byte injection + Boolean blind injection)
Log4j vulnerability elk platform processing method (logstah5.5.1)
Use webworker to perform background tasks
How to realize dynamic route switching and route caching in vuejs
Sword finger offer II 067. maximum XOR (medium prefix tree bit operation array)
Sword finger offer II 063. replacement word (medium prefix tree string)
75. Color classification (medium array double pointer sorting)
lotus 1.16.0 延长扇区过期时间
redis相关
Tensorflow serving high performance machine learning model service system
Hcip seventh experiment
76. Minimum coverage substring (hard sliding window hash table string)
npm ERR code ETIMEDOUT npm ERR syscall connect npm ERR errno ETIMEDOUT npm ERR network reques...
Att & CK Threat Intelligence
imx6q gpio复用
2022年一级建造师考试什么时候才能报名?
Openresty request authentication
For loops and functions
What are the main functions and uses of LCR tester