Files
python/TangDou/LuoGuBook/TestA.cpp

32 lines
845 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
int p[N];
char s[N], t[N];
int main() {
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;
}
while (true) {
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
}
cout << s << endl;
}
return 0;
}