There is a password problem on poj, And I feel this question is okay.
Bob and Alice started to use a brand new encoding system. It is based on a set of private keys. They chose n different numbers A1,..., An. They are all greater than 0 and less than or equal to n. The confidential process is as follows: the information to be encrypted is placed under this set of encryption keys, and the characters in the information correspond to the numbers in the Keys one by one. The letters at the I position in the information will be written to the AI position of the encrypted information, and AI is the key at the I position. The encrypted information is encrypted for a total of K times. The information length is less than or equal to n. If the information is shorter than N, spaces are used to fill the subsequent position until the information length is N. Please help Alice and Bob write a program, read the key, then read the encryption times K and the information to be encrypted, and encrypt the information according to the encryption rules.
Input
The input consists of several parts. Each row has a number N, 0 <n <= 200. The following row contains n different numbers. All numbers are greater than 0 and less than or equal to n. Each row below contains a K and an information string, which are separated by an empty lattice. Each line ends with a line break, which is not the information to be encrypted. The last row of each block has only one 0. The last block has a row, and the row has only one 0.
Output
The output contains multiple blocks, each of which corresponds to one input block. Each block contains the encrypted string of the information in the input, which is in the same order as the input. The length of all encrypted strings is N. Each block has a blank line.
Sample Input
104 5 3 7 2 8 1 6 10 91 Hello Bob1995 CERC00
Sample output
BolHeol bC RCE
The question result is actually related to the input array. It has nothing to do with the input string. If we do it directly, it will time out, timeout lies in unnecessary loops. Because each array repeats the current process after a certain number of times, we need to optimize the cycle of each array element loop.
#include<cstdio>
# Include <cstring> # include <iostream> using namespace STD; int main () {int N, I, K, X [210], J, l, m; char str1 [210], str2 [210]; while (CIN> N & n! = 0) {int y [210] = {0}; // used to store the for (I = 0; I <n; I ++) cycle of each array element to be cyclic) cin> X [I]; for (I = 0; I <n; I ++) {J = x [I]-1; while (true) {If (X [J]! = X [I]) {J = x [J]-1; y [I] ++;} else {Y [I] ++; break ;}}} while (scanf ("% d", & K )! = EOF & K! = 0) {getchar (); gets (str1); for (I = strlen (str1); I <n; I ++) str1 [I] = ''; for (I = 0; I <n; I ++) {M = I; for (j = 0; j <K % Y [I]; j ++) // at this time, after the remainder of the loop K, we can get the answer m = x [m]-1; str2 [m] = str1 [I];} str2 [N] = '\ 0'; puts (str2) ;}cout <Endl ;}}
Password problems poj 2818