AcWing 770. 单词替换
1. 地址
https://www.acwing.com/problem/content/772/
2. 题解
#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;
int main(){
string s;
string a,b;
string result = "";
getline(cin,s);
getline(cin,a);
getline(cin,b);
stringstream ssin(s); //将string对象初始化为stringstream对象,想使用stringstream对象,必须导入sstream头文件
string str;
while(ssin >> str){ //str读取stringstream中的内容,ssin跟cin用法相同,cin和ssin都代表遇到空格或回车就停止输入
if(str == a){
result = result + b + ' ';
}else{
result = result + str + ' ';
}
}
cout << result;
return 0;
}
标签:770,cin,ssin,单词,result,str,stringstream,AcWing,string
From: https://www.cnblogs.com/gao79135/p/17380841.html