2013年8月28日

UVa 10205 - Stack 'em Up

#include <cstdio>
#include <cstring>
#include <sstream>
using namespace std;

char value[13][9] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
char suit[4][9] = {"Clubs", "Diamonds", "Hearts", "Spades"};

int main() {
  char s[999];
  gets(s);
  int T;
  sscanf(s, "%d", &T);
  gets(s);
  while (T--) {
    gets(s);
    int n, shuffle[100][52];
    sscanf(s, "%d", &n);
    for (int i = 0; i < n; i++) {
      int index = 0;
      while (index < 52) {
        gets(s);
        istringstream ss(s);
        while (ss >> shuffle[i][index]) {
          index++;
        }
      }
    }
    int now[52];
    for (int i = 0; i < 52; i++) {
      now[i] = i;
    }
    while (gets(s) && s[0]) {
      int type;
      sscanf(s, "%d", &type);
      int next[52];
      for (int i = 0; i < 52; i++) {
        next[i] = now[shuffle[type - 1][i] - 1];
      }
      memcpy(now, next, sizeof(next));
    }
    for (int i = 0; i < 52; i++) {
      printf("%s of %s\n", value[now[i] % 13], suit[now[i] / 13]);
    }
    if (T) {
      puts("");
    }
  }
  return 0;
}

沒有留言:

張貼留言