字符串旋转问题:"abcdefgh" 向左旋转3个字符,"defghabc"
int gcd(int a,int b) {//求最大公约数 if(a==0||b==0) return -1; int t=a; if(a<b) { a=b; b=t; } while(b) { t=a%b; a=b; b=t; } return a; } void rotation(char *p,int n,int rotdist) {//旋转 int right=gcd(rotdist,n); for(int i=0;i<right;i++){ char t=p[i]; int j=i; while(true){ int k=j+rotdist; if(k>=n) k-=n; if(k==i) break; p[j]=p[k]; j=k; } p[j]=t; } }