abcd1234 4
sdfe123f 10
1234abcd
3fsdfe12
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 char s1[100]; 6 char s2[100]; 7 int k; 8 int length; 9 int i; 10 11 while(scanf("%s%d",&s1,&k)!=EOF){ 12 length=strlen(s1); 13 14 for(i=0;i<length;i++){ 15 if(i+k<=length-1) 16 s2[i+k]=s1[i]; 17 18 else 19 s2[(i+k)%length]=s1[i]; 20 } 21 s2[length]=‘\0‘; 22 23 printf("%s\n",s2); 24 } 25 return 0; 26 }
原文:http://www.cnblogs.com/zqxLonely/p/4100806.html