-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj-1026-置换群-scanf中的空格会读取多个.cpp
85 lines (83 loc) · 1.8 KB
/
poj-1026-置换群-scanf中的空格会读取多个.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<sstream>
using namespace std;
#define LOOP(x,y,z) for((x)=(y);(x)<=(z);(x)++)
#define LOOPB(x,y,z) for((x)=(y);(x)<(z);(x)++)
#define RLOOP(x,y,z) for((x)=(y);(x)>=(z);(x)--)
#define RLOOPB(x,y,z) for((x)=(y);(x)>(z);(x)--)
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define ABS(x) ((x)<0?-(x):(x))
#define PI 3.1415926535898
int i,j,k,a,m,n,s,t,l,tt,cas;
int num[211];
char str[211],ans[211];
bool chked[211];
int move[211],mt;
inline void do_move(int offset){
if(mt<=1||!offset)return;
int i,j=offset;
LOOPB(i,0,mt){
ans[move[j]]=str[move[i]];
j++;
if(j>=mt)j-=mt;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
#endif
while(scanf("%d",&n)!=EOF&&n){
LOOPB(i,0,n){
scanf("%d",&num[i]);
num[i]--;
}
scanf("%d",&m);
getchar();
while(m){
memset(chked,0,sizeof(chked));
gets(str);
if(strlen(str)<n){
LOOPB(i,strlen(str),n)
str[i]=' ';
str[n]=0;
}
strcpy(ans,str);
LOOPB(i,0,n){
if(!chked[i]){
mt=0;
move[mt++]=i;
chked[i]=true;
j=num[i];
while(j!=i){
move[mt++]=j;
chked[j]=true;
j=num[j];
}
do_move(m%mt);
}
}
ans[n]=0;
printf("%s\n",ans);
scanf("%d",&m);
getchar();
}
printf("\n");
}
}