Problem Description:
Suppose there is a string: ABCDE
L-One character get new string Bcdea
L two characters get new string Cdeab
Code implementation:
#include <stdio.h> #include <string.h>void reverse (char *left,char *right) {while (left<right) {char tmp= *left; *left=*right; *right=tmp; left++; right--; }}void Left_move (char *str,int k,int len) {reverse (str,str+k-1); reverse (str+k,str+len-1); reverse (str,str+len-1);} int main () {char str[]= "ABCDE";/* Original string: abcde*/int k=0; int Len=strlen (str); printf ("Please input rotate several characters:"); scanf ("%d", &k); while (K>len) {printf ("The number is too large, please re-enter:"); scanf ("%d", &k); } left_move (Str,k,len); printf ("%s\n", str); return 0;}
Results:
650) this.width=650; "title=" _}1u) 6}c19nonluz[puja{t.png "src=" http://s2.51cto.com/wyfs02/M02/76/7D/ Wkiol1zueqgagmclaaajzeaoark332.png "alt=" Wkiol1zueqgagmclaaajzeaoark332.png "/>
This article is from the "Pzd Chuan Feng" blog, please make sure to keep this source http://xujiafan.blog.51cto.com/10778767/1716553
C language-->> left-handed string