You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
845 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
2 years ago
const int N = 210;
2 years ago
2 years ago
int p[N];
char s[N], t[N];
2 years ago
int main() {
2 years ago
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x; // 输入的是 4 1 2 3 ,映射成: 3 0 1 2,改成下标从0开始方便后续计算
p[i] = x - 1;
}
2 years ago
while (true) {
2 years ago
int m;
cin >> m;
if (m == 0) break;
cin >> s; // cin输入字符数组与string没什么区别
// 补空格
for (int i = strlen(s); i < n; i++) s[i] = ' ';
for (int i = 1; i <= m; i++) { // 加密m次
for (int j = 0; j < n; j++) // 每个字符
t[p[j]] = s[j]; // 替换
memcpy(s, t, sizeof t); // 还原为s
2 years ago
}
2 years ago
cout << s << endl;
2 years ago
}
return 0;
}