Files
python/TangDou/LuoGuBook/TestA.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

32 lines
845 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}