//Left rotation string Abcdefgh->cdefghab//Cyclic recursion method#include <iostream>#include <string.h>using namespace Std;voidRunstring (Char*Str,intN) {inti =0;intj = i+n;intLen = strlen (Str);Char*p =Str;CharCh while(J<len) { for(intm=0; m<n;m++) {if(p[j]==' + ') Break; ch = p[i]; P[I]=P[J]; P[j]=ch; i++;j++; } }//At this point the cab behind the DEFGH cab needs to be rotated. for(intk=0; k<n-len%n;k++) {the string that needs to be rotated on the last face is len%n, because n bits are not satisfied, so I first swap the len%n bit, //So just check the n-len%n bit can convert the number, so I will be the rest of the right rotation.Ch=p[i];intM for(m=i;m<len-1; m++) {p[m]=p[m+1]; } p[m]=ch; }}intMain () {Char Str[]="ABCDEFGHMK"; Runstring (Str,3);//A total of 10 bits, and we need 3 bit of rotation, then what? cout<<Str<<endl;return 0;}//< pointer reversal method >#include <iostream>//Once the number of mobile digits is not enough, jump out of the loop and start moving.#include <string.h>iusing namespace Std;voidRunstring (Char*Str,intN) {if(n<=0||Str==null)return;//char *fptr = str; //char *lptr = str+n; Char*p =Str;intLen = strlen (Str);inti =0;intj = i+n;// intKCharCh while(len-j>=n) { for(k=0; k<n;k++) {ch = p[j]; P[J] = P[i]; P[i] = ch; i++; j + +; }} n = len-j; for(k=0; k<n;k++) {ch = p[len-1];int sum= len-1; for(intm =0; m<=j-i;m++) {p[sum] = p[sum-1];sum--; } p[sum]=ch; }}intMain () {Char Str[]="ABCDEFGHLM"; Runstring (Str,4); cout<<Str<<endl;return 0;}//< Violent Displacement law >#include <iostream>#include <string.h>using namespace Std;voidRunstring (Char*Str,intN) {if(Str==null | | n==0)return;if(n>0) { for(intI=0; i<n;i++) {Char*p =Str;Charch=p[0]; while(*p!=' + ') {*p=* (p+1); p++; } * (P-1) = CH; } }Else{intm = strlen (Str); for(intI=0; i<-n;i++) {Char*p =Str+m-1;Charch = *p;intSave = M1; while(M-1>0) {*p = * (P-1); p--; m--; } *p=ch; M=save; } }}intMain () {Char Str[]="ABCDEFGH"; Runstring (Str,0); cout<<Str<<endl;return 0;}
C + + left-handed string