文章

224

粉丝

0

获赞

905

访问

34.7k

头像
单词替换 题解:
P1196 北京大学上机题
发布于2026年3月16日 10:51
阅读数 6

#include<iostream>
#include<vector>
using namespace std;

string str,res;
vector<string> ans;

int main()
{
    getline(cin,str);
    string a,b;
    cin>>a>>b;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]==' ')
        {
            if(res!=a)
            ans.push_back(res);
            else
            ans.push_back(b);
            res="";
        }
        else
        res+=str[i];
    }
    if(res!=a)
    ans.push_back(res);
    else
    ans.push_back(b);
    for(auto s:ans)
    cout<<s<<" ";
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发