标签:des style blog class code tar
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 18970 | Accepted: 5067 |
Description
Input
Output
Sample Input
10 4 5 3 7 2 8 1 6 10 9 1 Hello Bob 1995 CERC 0 0
Sample Output
BolHeol b C RCE
求置换的循环节
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #define MAX 202 5 int key[MAX], t[MAX]; 6 void get_time(int n) 7 { 8 int i, j, count; 9 for (i = 1; i <= n; i++) 10 { 11 j = key[i]; 12 count = 1; 13 while(i != j) 14 { 15 count++; 16 j = key[j]; 17 } 18 t[i] = count; 19 } 20 } 21 int main() 22 { 23 int i, j, k, n, len; 24 char src[MAX], dst[MAX]; 25 26 while(scanf("%d", &n)&&n) 27 { 28 for (i = 1; i <= n; i++) 29 scanf("%d", &key[i]); 30 memset(t, 0, sizeof(t)); 31 get_time(n); 32 while(scanf("%d", &k)&&k) 33 { 34 getchar(); 35 gets(src + 1); 36 for (i = strlen(src + 1) + 1; i <= n; i++) 37 src[i] = ‘ ‘; 38 src[n + 1] = 0; 39 for (i = 1; i <= n; i++) 40 { 41 int pos = i; 42 for (j = 0; j < k % t[i]; j++) 43 pos = key[pos]; 44 dst[pos] = src[i]; 45 } 46 dst[n + 1] = 0; 47 puts(dst + 1); 48 } 49 printf("\n"); 50 } 51 return 0; 52 }
标签:des style blog class code tar
原文地址:http://www.cnblogs.com/lxm940130740/p/3720328.html