http://acm.zjgsu.edu.cn/JudgeOnline/showproblem?problem_id=1259
#include<iostream>
#include
<string>
#include
<cstdio>
using namespace std;
int st[83][83];
int main()
{
    
int n;
     __int64 kk;
    
while(scanf("%d%I64d",&n,&kk) && n+kk)
    
{
        
int i,j,pp;
        
char str[83],temp[83];
        
int sh[83],xia[83];
        
for(i=0;i<n;i++)
        
{
            cin
>>pp;
            pp
--;
            sh[i]
=pp;//第i个位置要拿到pp
            xia[pp]=i;
        }
 
        getchar();
        cin.getline(str,
82,'\n');
        
for(i=0;i<n;i++)
        
{
            j
=xia[i];
            pp
=1;
            
while(i!=j)
            
{
                st[i][pp
++]=j;
                j
=xia[j];
            }

            st[i][pp]
=st[i][pp+1]=j;
            st[i][
0]=pp;//循环次数
        }

        
for(i=0;i<n;i++)
        
{
            
if(kk%st[i][0]==0)
                pp
=st[i][0];
            
else
            
{
                pp
=kk%st[i][0];
                pp
=st[i][0]-pp;//
            }

            temp[st[i][pp]]
=str[i];            
        }

        temp[n]
='\0';
        printf(
"%s\n",temp);
    }

    
return 0;
}