当前位置:网站首页>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;
}
边栏推荐
- SSH password free login
- LVS+KeepAlived高可用部署实战应用
- imx6q gpio复用
- mysql create语句能不能用来建立表结构并追加新的记录
- 删除容器镜像报错解决image is referenced in multiple repositories
- [CVPR 2021] cylinder3d: cylindrical asymmetric 3D convolution network for LIDAR point cloud segmentation
- If you want to grow rapidly, you must first experience a major blow!
- LeetCode刷题系列之-多数之和类型
- Use REM to make the font size adaptive to the screen
- NPM switch Taobao source (NPM source)
猜你喜欢

(翻译)图技术简明历史

Ultra detailed visual studio 2019 running littlevgl (lvgl) simulator

Mysql内置函数

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

XXX port is already in use

软考网络工程师

Static details of static members

Paddlenlp text classification based on ernir3.0: take wos dataset as an example (hierarchical classification)

842. 排列数字

Which is the file transfer command in the basic services of the Internet
随机推荐
成立不到一年!MIT衍生量子计算公司完成900万美元融资
What is time complexity
Leetcode question brushing series - sum of majority type
PHP库neo4j怎么安装及使用
Baidu map usage
Closure, prototype and original link
PaddleNLP基于ERNIR3.0文本分类以中医疗搜索检索词意图分类(KUAKE-QIC)为例【多分类(单标签)】
What does GPRS network mean
Target segmentation learning
删除容器镜像报错解决image is referenced in multiple repositories
log4j漏洞 elk平台 处理方法 (logstah5.5.1)
[CS231N]Lecture_ 2:Image Classification pipelin
npm ERR code ETIMEDOUT npm ERR syscall connect npm ERR errno ETIMEDOUT npm ERR network reques...
MySQL command (add, delete, check and modify)
容器化配置启动redis集群 单机6节点 3主3从
Static route and default route experiment
For loops and functions
AWK空行过滤
Common commands of NPM
Win11怎么打开软件通知