题解 | #单词替换#

单词替换

http://www.nowcoder.com/practice/5b58a04679d5419caf62c2b238e5c9c7

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main() {
    string str, str1, str2, temp;
    int low, high;
    while (getline(cin, str)) {
        getline(cin, str1);
        getline(cin, str2);
        low = high = 0;
        while (high < str.size()) {
            while (str[high] != ' ' && high < str.size())++high;
            temp=str.substr(low, high - low);
            if (str1 == temp) {
                str.erase(low, high - low);
                str.insert(low, str2);
            }
            else {
                low = ++high;
            }
        }
        cout<<str<<endl;
    }
    return 0;
}

全部评论

相关推荐

09-10 15:05
已编辑
门头沟学院 游戏后端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务