Problem link:
306 - Cipher
Solution:
306 - Cipher
Solution:
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int S = 203;
- const int MOD = 1e9+7;
- const double pi = 2 * acos (0.0);
- int _I(){int x; scanf("%d", &x); return x;}
- LL _LL(){LL x; scanf("%lld", &x); return x;}
- int dirX[]={1, 0, -1, 0, 1, -1, 1, -1};
- int dirY[]={0, 1, 0, -1, 1, -1, -1, 1};
- int rX[] = {1, 1, 2, 2, -1, -1, -2, -2};
- int rY[] = {2, -2, 1, -1, 2, -2, 1, -1};
- template <class T> T Distance(T x1, T y1, T x2, T y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));};
- int sset(int N, int pos){return N=N|(1<<pos);}
- bool check(int N, int pos){return (bool)(N&(1<<pos));}
- int reset(int N, int pos){return N=N&~(1<<pos);}
- ///...............Code Starts From Here...............///
- char ans[S];
- char input[S];
- int number[S];
- int main(){
- int n;
- while(scanf("%d", &n) == 1 && n){
- for(int i = 0; i < n; i++)number[i] = _I()-1;
- int k;
- while(scanf("%d", &k) == 1 && k){
- getchar();
- gets(input);
- memset(ans, ' ', sizeof(ans));
- int ind, cn;
- for(int i = 0; input[i]; i++){
- ind = i, cn = 0;
- int f = 0;
- while(cn < k){
- if(ind == i && f){
- f = 2;
- break;
- }
- ind = number[ind];
- cn++, f = 1;
- }
- int p = k%cn;
- if(f == 2){
- ind = i, cn = 0;
- while(cn < p){
- ind = number[ind];
- cn++;
- }
- }
- ans[ind] = input[i];
- }
- for(int i = 0; i < n; i++)printf("%c", ans[i]);
- puts("");
- }
- puts("");
- }
- return 0;
- }
ラッキーニッキー ラッキーニッキー 카지노 카지노 dafabet dafabet bet365 bet365 bk8 bk8 カジノ シークレット カジノ シークレット 카지노 카지노 171
ReplyDelete