Drolca

Apologize To Drolca
随笔 - 28, 文章 - 1, 评论 - 6, 引用 - 0
数据加载中……

1026

#include <iostream>
using namespace std;

const int maxn=205;
int qun[maxn];
char res[maxn];
char str[maxn];
int t[maxn];
int n;
void getT()
{
    
int i,j;
    
for(i=1;i<=n;i++)
    
{
        
if(t[i]==0)
        
{
            
int cnt=1;
            
int top=-1;
            
int same[maxn];
            
int pos=qun[i];
            
while(pos!=i)
            
{
                same[
++top]=pos;
                pos
=qun[pos];
                cnt
++;
            }

            t[i]
=cnt;
            
for(j=0;j<=top;j++)
                t[same[j]]
=cnt;
        }

    }

}

int main()
{

    
while(scanf("%d",&n)!=EOF&&n)
    
{
        
int i,j;
        
for(i=1;i<=n;i++)
            scanf(
"%d",&qun[i]);
        memset(t,
0,sizeof(t));
        
        getT();
        
int k;
        
while(scanf("%d",&k)!=EOF&&k)
        
{
            memset(res,
'\0',sizeof(res));
            memset(str,
'\0',sizeof(str));
            gets(str);
            
for(i=1;i<=n;i++)
            
{
                
int tmp=i;
                
for(j=0;j<k%t[i];j++)
                    tmp
=qun[tmp];
                
if(str[i]=='\0') res[tmp]=' ';
                
else res[tmp]=str[i];
            }

            printf(
"%s\n",res+1);
        }

        printf(
"\n");
    }

    
return 0;
}

posted on 2009-09-06 10:51 Drolca 阅读(59) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理