AcWing 1526. 洗牌机
原题链接
简单
作者:
巨鹿噜噜噜路
,
2020-05-27 17:57:34
,
所有人可见
,
阅读 724
C++ 代码
#include <iostream>
#include <cstring>
using namespace std;
const int MAX_N = 54;
int poker[MAX_N + 1];
int seq[MAX_N + 1];
int tmp[MAX_N + 1];
int main() {
int k;
cin >> k;
for (int i = 0; i < MAX_N; i++) {
poker[i] = i;
int x;
cin >> x;
seq[i] = x - 1;
}
while (k--) {
for (int i = 0; i < MAX_N; i++) {
tmp[seq[i]] = poker[i];
}
memcpy(poker, tmp, sizeof(poker));
}
char stands[] = "SHCDJ";
for (int i = 0; i < MAX_N; i++) {
if (i) printf(" ");
int idx = poker[i] / 13;
int num = poker[i] % 13 + 1;
printf("%c%d", stands[idx], num);
}
return 0;
}