C++ 代码
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
int n;
cin >> s >> n;
while(n--)
{
int l,r;
string s1,s2;
cin >> l >> r >> s1 >> s2;
string cp = s.substr(l-1,r-l+1);
s.erase(l-1,r-l+1);
string s3 = s1 + s2;
size_t pos = s.find(s3);
if(pos == string::npos)
s += cp;
else
s.insert(pos + s1.size(),cp);
}
cout << s;
return 0;
}