当前位置:网站首页>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;
}
边栏推荐
- The function of wechat applet to cut pictures
- Hcip experiment (14)
- 想要快速成长,先要经历重大打击!
- Sword finger offer II 064. magic Dictionary (medium dictionary tree string design)
- 【二叉树】二叉树中的伪回文路径
- Awk blank line filtering
- HCIP(13)
- Ukrainian officials: half of Ukrainian agricultural products are exported through the Danube port
- Att & CK preliminary understanding
- SQL injection less34 (post wide byte injection + Boolean blind injection)
猜你喜欢

PaddleNLP基于ERNIR3.0文本分类:WOS数据集为例(层次分类)

98. Verify binary search tree (medium binary search tree DFS)

npm ERR code ETIMEDOUT npm ERR syscall connect npm ERR errno ETIMEDOUT npm ERR network reques...

MySQL built-in functions

Static route and default route experiment
![[CVPR 2021] cylinder3d: cylindrical asymmetric 3D convolution network for LIDAR point cloud segmentation](/img/3d/3def78ec88419712e14cf437e21447.png)
[CVPR 2021] cylinder3d: cylindrical asymmetric 3D convolution network for LIDAR point cloud segmentation
Integrating database Ecology: using eventbridge to build CDC applications

(翻译)图技术简明历史
![[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login](/img/53/c578e0d1428ea569fb412a20019924.png)
[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login

Ngrok intranet penetration
随机推荐
[leetcode] maximum depth of binary tree
Overall introduction of Ruiji takeout project
Jianzhi offer II 062. implement prefix tree (medium design dictionary tree prefix tree string)
Less than a year after its establishment! MIT derivative quantum computing company completed financing of US $9million
Tensorflow serving high performance machine learning model service system
2021 mathematical modeling group B code
Ngrok intranet penetration
JMeter installs third-party plug-ins plugins Manager
Sword finger offer II 065. The shortest word code (medium dictionary tree string array)
[CS231N]Lecture_ 2:Image Classification pipelin
JS implementation generates a random key of specified length
20-09-27项目迁移到阿里折腾记录(网卡顺序导致服务无法通过haproxy连接到db)
Container configuration starts redis cluster single machine 6 nodes 3 Master 3 slave
容器化配置启动redis集群 单机6节点 3主3从
【转载】token令牌在登录场景使用
PaddleNLP基于ERNIR3.0文本分类以CAIL2018-SMALL数据集罪名预测任务为例【多标签】
ECMASript 5/6 笔记
HCIP(13)
LCR测试仪最为主要的功能和用途都是什么
HCIP(12)