爱奇艺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;
}

#爱奇艺##笔试题目#
全部评论

相关推荐

我已成为0offer的糕手:走算法要发论文的,至少你简历上一篇没有,这个薪资估计没戏了,实习和论文都没有,你不如先考虑考虑算法这条路,会不会因为本科学历把你的简历直接给刷了,转开发吧
点赞 评论 收藏
分享
09-25 13:56
门头沟学院 Java
点赞 评论 收藏
分享
1 1 评论
分享
牛客网
牛客企业服务