#include<iostream> #include<string> using namespace std; int main(){ int n,i,k,item=1,sum=1,sum1; int i1; char * *message1; char * *message2; do{ cin>>n; if(n==0)break; int * sequen_num=new int[n]; int * s=new int[n]; char * message=new char[n]; char * str=new char[n+1]; for(i=0;i<n;i++){ cin>>sequen_num[i]; } sum1=1; message1=(char **)malloc(sizeof(char *)*sum1); for(i=0;i<sum1;i++) message1[i]=new char[n]; do{ for(i=0;i<n+1;i++){ str[i]=' '; message[i]=' '; } cin>>k; if(k==0)break; char sc; for(i=0;i<n+1;i++){ sc=getchar(); if(sc==' ') break; str[i]=sc; } for(i=0;i<n;i++){ item=i; sum=1; while(1){ item=sequen_num[item]-1; s[sum-1]=item; if(i==item) break; sum++;//sum 个循环 } message[s[(k-1)%sum]]=str[i+1]; } for(i=0;i<n;i++) message1[sum1-1][i]=message[i]; sum1++; message2=(char **)malloc(sizeof(char *)*sum1); for(i=0;i<sum1;i++) message2[i]=new char[n]; for(i=0;i<sum1-1;i++) for(i1=0;i1<n;i1++) message2[i][i1]=message1[i][i1]; for(i=0;i<sum1-1;i++) delete message1[i]; message1=message2; }while(1); for( i1=0;i1<sum1-1;i1++){ for(i=0;i<n;i++) cout<<message1[i1][i]; cout<<endl; } cout<<endl; }while(1); return 0; }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com