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

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

相关推荐

1 1 评论
分享
牛客网
牛客企业服务