2011.网研院.Problem A.字符串操作
Description
大家平时都会用到字符串,现在有几种字符串操作,需要你用这几种操作处理下字符串。
Input
多组数据,以EOF结束。
第一行一个字符串,字符串长度大于0,并且小于等于200。
第二行一个数字t,(0<t<=200)。
下面t行,每行表示一种操作。
共有两种操作,每行数据的第一个数表示操作的种类:
翻转操作:第一个是一个数字0,然后两个数字i和len,翻转从下标i长度为len的子串。
替换操作:第一个是一个数字1,然后两个数字i和len,接着一个长度为len的字符串str,用str替换从下标i长度为len的子串。
字符串操作后会更新,旧的字符串被舍弃。(详见sample)
Output
每个操作之后输出生成的新的字符串
Sample Input
bac
2
0 0 3
1 1 2 as
Sample Output
cab
cas
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
while(cin>>s){
int t,op,st,len;
string tmp;
cin>>t;
while(t--){
cin>>op>>st>>len;
if(op==0){
reverse(s.begin()+st,s.begin()+st+len);
}
if(op==1){
cin>>tmp;
s.erase(st,len);
s.insert(st,tmp);
}
cout<<s<<endl;
}
}
return 0;
}
还没有评论,来说两句吧...