直接模拟就好。
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <climits> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);} const char* kind[] = {"Clubs","Diamonds","Hearts","Spades"}; const char* num[] = {"Jack","Queen","King","Ace"}; char tmp[5]; int ord[110][60],N; int cards[60],ct[60]; int main() { //freopen("sample.txt","r",stdin); int T; scanf("%d",&T); while (T--) { scanf("%d",&N); for (int i = 1; i <= N; i++) for (int j = 1; j <= 52; j++) scanf("%d",&ord[i][j]); for (int i = 1; i <= 52; i++) cards[i] = i; getchar(); while (gets(tmp) && tmp[0]!='\0') { int x ; sscanf(tmp,"%d",&x); for (int i = 1; i <= 52; i++) ct[i] = cards[ord[x][i]]; memcpy(cards,ct,sizeof(cards)); } for (int i = 1; i <= 52; i++) { int t = (cards[i] - 1) % 13; if (t < 9) printf("%d",t + 2); else printf ("%s",num[t % 9]); printf(" of "); printf("%s\n",kind[(cards[i] - 1) / 13]); } if (T) putchar('\n'); } return 0; }