#include <iostream> #include <string> using namespace std; const int Max=100; char *sreverse(char *s,int a,int b) { char e; char c; if(b>a) { c=s[a]; e=s[b]; s[a]=e; s[b]=c; a++; b--; sreverse(s,a,b); } return s; } int main() { int i; char *a=new char[Max]; char *p; cin>>a; cin>>i; if(i==0) cout<<a<<endl; else if(i<0){ i=-i; sreverse(a,0,i-1); sreverse(a,i,strlen(a)-1); p=sreverse(a,0,strlen(a)-1); cout <<p<<endl; } else { sreverse(a,strlen(a)-i,strlen(a)-1); sreverse(a,0,strlen(a)-i-1); p=sreverse(a,0,strlen(a)-1); cout <<p<<endl;
} return 0; }
能不能进行优化啊,超时!!!
|