//3. Implement a function that can left-hand k characters in a string. //ABCD rotates one character to the left to get BCDA //ABCD rotates two characters to the left to get CDAB

#include<stdio.h>
#include<stdlib.h>
int move(char arr[5],int sz,int k)
{
while (k)
{
int i = 0;
int temp = arr[0];
for (i = 1; i <= sz; i++)
{
arr[i - 1] = arr[i];
}
arr[sz - 1] = temp;
k--;
}
return arr;
}


int main()
{
char arr[5] = "ABCD";
int sz = strlen(arr);
int k = 0;
scanf("%d", &k);
printf("%s\n", move(arr, sz, k));
system("pause");
return 0;
}

Guess you like

Origin blog.csdn.net/lxp_mujinhuakai/article/details/54379139