首页 > 爱奇艺8.23算法笔试第一题
头像
止水201808182114128
编辑于 2020-08-23 19:57
+ 关注

爱奇艺8.23算法笔试第一题

#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    string org, match;
    while (getline(cin, org)){
        getline(cin, match);
        string res;
        for (int i = 0; i < org.size(); ++i) {
            if(org[i]!=match[0]){
                res += org[i];
            }else{
                int index_org=i+1;
                int index_match = 1;
                bool flag = true;
                while(true){
                   if(org[index_org]==' '){
                       index_org +=1;
                   }else{
                       if(org[index_org]!=match[index_match]){
                           flag = false;
                       }else{
                           index_org += 1;
                           index_match += 1;
                       }
                   }
                   if(index_match>=match.size()){
                       break;
                   }
                   if(flag==false){
                       break;
                   }
                }
                if(flag){
                    if(i>=1&&org[i-1]!=' ') {
                        res += ' ';
                    }
                    res += match;
                    res += ' ';
                    i = index_org-1;
                }else{
                    res += org[i];
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

全部评论

(0) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐