版权声明:本人小白,有错误之处恳请指出,感激不尽;欢迎转载 https://blog.csdn.net/stone_fall/article/details/88725429
时间限制 1000 ms 内存限制 65536 KB Special Judge
题目描述
大家平时都会用到字符串,现在有几种字符串操作,需要你用这几种操作处理下字符串。
HINT
字符串下标从0开始,所有操作的数据范围都合乎规范。
输入格式
多组数据,以EOF结束。
第一行一个字符串,字符串长度大于0,并且小于等于200。
第二行一个数字t,(0<t<=200)。
下面t行,每行表示一种操作。
共有两种操作,每行数据的第一个数表示操作的种类:
翻转操作:第一个是一个数字0,然后两个数字i和len,翻转从下标i长度为len的子串。
替换操作:第一个是一个数字1,然后两个数字i和len,接着一个长度为len的字符串str,用str替换从下标i长度为len的子串。
字符串操作后会更新,旧的字符串被舍弃。(详见sample)
输出格式
每个操作之后输出生成的新的字符串
输入样例
bac
2
0 0 3
1 1 2 as
输出样例
cab
cas
AC代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
string str;
while(cin>>str){
int t,op,i,len;
cin>>t;
while(t--){
cin>>op>>i>>len;
if(op==0){
reverse(str.begin()+i,str.begin()+i+len);
}
else{
string re;
cin>>re;
str.replace(i,len,re);
}
cout<<str<<endl;
}
}
return 0;
}