L1-6 剪切粘贴

发布时间 2023-12-18 21:07:38作者: 纯粹的

原题链接

看代码,懂得都懂,不懂就真不懂

#include <bits/stdc++.h>
using namespace std;
string str, head, send;
int N, M, K;
int main()
{
    cin >> str;
    cin >> N;
    while (N--)
    {
        cin >> M >> K >> head >> send;
            M--;K--;
        string T = str.substr(M ,K - M + 1);
        str.erase(M, K - M + 1);
        if (str.find(head + send) != str.npos)
        {
            str = str.substr(0, str.find(head + send) + head.size()) + T + str.substr(str.find(head + send) + head.size());
        }
        else
            str += T;
    }
    cout << str << endl;
    return 0;
}