poj 1026 Cipher

时间:2022-04-21 18:07:24

置换群就可以搞定!!!

注意下格式就好了……

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stdlib.h>
#include<cstring>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define MAX 50000
using namespace std;
int code[],an[];
char str1[],str2[];
void init(int n)
{
int i,j,t;
for (i=;i<=n;i++){
j = i;
t = ;
while (code[j]!=i) j = code[j],t++;
an[i] = t+;
}
}
int main(){
int n,m,i,j,k,t;
while (cin>>n&&n){
for (i=;i<=n;i++)
cin>>code[i];
init(n);
while (scanf("%d",&k)!=EOF&&k){
getchar();
gets(str1+);
for (i=strlen(str1+)+;i<=n;i++)
str1[i] =' ';
for (i=;i<=n;i++){
t = k%an[i];
j = i;
if (t==) str2[i] = str1[i];
while (t--){
j = code[j];
}
str2[j] = str1[i];
}
for (i=;i<=n;i++)
cout<<str2[i];
cout<<endl;
}
cout<<endl;
}
return ;
}