[AcWing 770] 单词替换

image


点击查看代码
#include<iostream>
#include<sstream>

using namespace std;
string s, a ,b;

int main()
{
    getline(cin ,s);
    cin >> a >> b;
    stringstream ssin(s);
    string str;
    while (ssin >> str) {
        if (str == a)   cout << b << ' ';
        else    cout << str << ' ';
    }
    return 0;
}

stringstream ssin(s);
定义一个字符串输入流的对象ssin,并调用ssin的复制构造函数,将s中所包含的字符串放入ssin对象中

posted @ 2022-04-14 10:41  wKingYu  阅读(47)  评论(0)    收藏  举报