C + + left-handed string

Source: Internet
Author: User

//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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.