题目:http://10.105.242.80/problem/p/107/
坑1.字符串输入可以有空格
坑2.有空格使用gets()函数,需要在一些地方使用getchar()函数吃掉回车
坑3.翻转时索引不一定从0开始,截取一半进行翻转时要小心
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
char buf[210];
while(gets(buf)){
string s(buf);
int order,index,len;
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&order,&index,&len);
if(order==0){
getchar();
for(int i=index,j=index+len-1;i<j;i++,j--){
char c=s[i];
s[i]=s[j];
s[j]=c;
}
printf("%s\n",s.c_str());
}else if(order==1){
char buf2[210];
scanf("%s",buf2);
getchar();
string ns(buf2);
for(int i=0;i<len;i++){
s[i+index]=ns[i];
}
printf("%s\n",s.c_str());
}
}
}
return 0;
}
参考博客:https://blog.csdn.net/u012963208/article/details/64158119