#include<stdio.h> char s[120]; char cmd[120]; int start; int len; int n; void SWAP(char *a,char *b) { char t=*a; *a=*b; *b=t; } void reverse() { for(int i=start,j=start+len-1;i<j;++i,--j) SWAP(&s[i],&s[j]); printf("%s\n",s); } void replace() { int k=3; for(int i=start;i<start+len;++i,k++) { s[i]=cmd[k]; } printf("%s\n",s); } int main(int argc, char *argv[]) { // freopen("1177.in", "r", stdin); while(~scanf("%s%d",s,&n)) { while(n--){ scanf("%s",cmd); if(cmd[0]=='0') { start=cmd[1]-'0'; len=cmd[2]-'0'; reverse(); } else { start=cmd[1]-'0'; len=cmd[2]-'0'; replace(); } } } return 0; } /************************************************************** Problem: 1177 User: kirchhoff Language: C Result: Accepted Time:0 ms Memory:912 kb ****************************************************************/
原文地址:http://blog.csdn.net/wdkirchhoff/article/details/41944211