文章
2
粉丝
60
获赞
0
访问
1.3k
#include<bits/stdc++.h>
using namespace std;
void reverse(string &s, int begin, int end) {
for (int i = begin, j = end; i < j; i++,j--) {
swap(s[i],s[j]);
}
}
int main() {
string str;
while (cin>>str) {
int n;
cin>>n;
for (int i = 0; i < n; i++) {
string s;
cin>>s;
//反转
if (s[0] == '0') {
int begin = s[1]-'0';
int end = s[2]-'0'+begin-1;
reverse(str, begin, end);
cout<<str<<endl;
}
else if (s[0] == '1') {
int begin = s[1]-'0';
int end = s[2]-'0'+begin-1;
string s1 = s.substr(3, s.size());
str.erase(str.begin()+begin, str.begin()+end+1);
str.insert(begin,s1);
cout<<str<<endl;
}
}
}
return 0;
}
登录后发布评论
注意审题,替换操作的题意没理解对