Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Subject to the effect: Enter shuffle order to get the final result.
Use sta, sca, end three arrays are stored the initial state, the end state and sequencing requirements; each sta before the end assigned to the start shuffle, and then use the value stored sca to the sta end. Note array of characters define how the output.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int n;
cin>>n;
int sta[55], end[55], sca[55];
for (int i = 1; i < 55; i++) {
scanf("%d", &sca[i]);
end[i] = i;
}
for (int i = 0; i < n; i++) {
for (int j = 1; j < 55; j++) {
sta[j] = end[j];
}
for (int k = 1; k < 55; k++) {
end[sca[k]] = sta[k];
}
}
char c[6] = {"SHCDJ"};
for (int i = 1; i < 55; i++) {
end[i]-=1;
printf("%c%d", c[end[i] / 13], end[i] % 13 + 1);
if (i != 54) printf(" ");
}
return 0;
}