错的快抑郁了
#include<stdio.h> #include<string.h> #define MAX 300 int key[MAX],round[MAX]; char str1[MAX],str2[MAX]; int main() { int i,n,k,temp,count; char ch; while(scanf("%d",&n),n!=0) { for(i=0;i<n;i++) scanf("%d",&key[i]); for(i=0;i<n;i++) { temp=i; count=0; do { temp=key[temp]; temp--; count++ ; }while(temp!=i); round[i]=count; } while(scanf("%d",&k),k!=0) { getchar(); i=0; while((ch=getchar())!='\n') str1[i++]=ch; while(i<n) str1[i++]=' '; for(i=0;i<n;i++) { count=k%round[i]; temp=i; while(count--) { temp=key[temp]; temp--; } str2[temp]=str1[i]; } str2[n]='\0'; printf("%s\n",str2); } printf("\n"); } return 0; }