当前位置:网站首页>770. Word replacement
770. Word replacement
2022-07-28 22:38:00 【Hunter_ Kevin】
subject
Enter a string , End with a carriage return ( The string length does not exceed 100).
The string consists of several words , Words are separated by a space , All words are case sensitive .
Now we need to replace one word with another , And output the replaced string .
Input format
Input common 3 That's ok .
The first 1 A line is a string containing multiple words s;
The first 2 Line is the word to be replaced a( Length not exceeding 100);
The first 3 Line is a The word to be replaced b( Length not exceeding 100).
Output format
All in one line , The output will s All words in a Replace with b String after .
sample input :
You want someone to help you
You
I
sample output :
I want someone to help you
Code
#include <iostream>
#include <sstream> // needed stringstream The header file
using namespace std;
int main()
{
string s, a, b;
getline(cin, s);
cin >> a >> b;
stringstream ssin(s);// Convert string to character stream , after ssin Be similar to cin, The difference is that ssin You can stream from the specified character s Read string from
string tmp;// Store temporary slave character streams s String read from
while(ssin >> tmp)// Always stream from character stream s Read the string to tmp in
if(tmp == a) cout << b << ' ';// If tmp == a, The output b
else cout << tmp << ' ';// Otherwise, the original string is output
return 0;
}
边栏推荐
- 容器化配置启动redis集群 单机6节点 3主3从
- How to realize dynamic route switching and route caching in vuejs
- 770. 单词替换
- fatal error: io. h: No such file or directory
- Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)
- 32. Longest valid bracket (difficult stack string)
- Day3 classification management of Ruiji takeout project
- PaddleNLP基于ERNIR3.0文本分类:WOS数据集为例(层次分类)
- JS获取当前时间(年月日时分秒)
- internet的基本服务中文件传输命令是哪个
猜你喜欢

mysql create语句能不能用来建立表结构并追加新的记录

How to install WiFi correctly

6K6w5LiA5qyh5pS75Ye75YiG5p6Q

MySQL installation and configuration (super detailed, simple and practical)

基于Ernie-3.0 CAIL2019法研杯要素识别多标签分类任务

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

Sword finger offer II 055. Binary search tree iterator (medium binary search tree iterator)

Att & CK Threat Intelligence

成立不到一年!MIT衍生量子计算公司完成900万美元融资

Imx6q GPIO multiplexing
随机推荐
PaddleNLP基于ERNIR3.0文本分类以CAIL2018-SMALL数据集罪名预测任务为例【多标签】
[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login
mysql create语句能不能用来建立表结构并追加新的记录
76. Minimum coverage substring (hard sliding window hash table string)
How about the actual use effect of common source oscilloscope
79. Word search (medium string array matrix backtracking)
DOM programming + events
Idea generate class diagram plug-in UML (super detailed)
Wechat applet uses canvas drawing, round avatar, network background, text, dotted line, straight line
When can I sign up for the 2022 class I constructor examination?
Target segmentation learning
Concise history of graphic technology
There will be a black line on the border when the button in the wechat applet is clicked
删除容器镜像报错解决image is referenced in multiple repositories
LVS+KeepAlived高可用部署实战应用
How do we do full link grayscale on the database?
(翻译)图技术简明历史
MOV格式是不是静态图像文件格式
软考网络工程师
Solve Jupiter: the term 'Jupiter' is not recognized as the name of a cmdlet, function, script file