UVa : 10205 ( Stack ’em Up)



// http://uva.onlinejudge.org/external/102/10205.html

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;

int shuffles [100 + 5] [52 + 3];
map <int, string> cardName;

void reset ()
{
	string suit [] = { "Clubs", "Diamonds", "Hearts", "Spades" };
	string value [] = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };

	int cardNum = 1;

	for ( int i = 0; i < 4; i++ ) {
		for ( int j = 0; j < 13; j++ )
			cardName [cardNum++] = value [j] + " of " + suit [i];
	}

}

int main ()
{
	int testCase;
	scanf ("%d", &testCase);
	bool blank = false;

	reset ();

	while ( testCase-- ) {
		int n;
		scanf ("%d", &n);

		for ( int i = 1; i <= n; i++ ) {
			for ( int j = 1; j <= 52; j++ ) scanf ("%d", &shuffles [i] [j]);
		}
		getchar ();

		int present [52 + 3];

		for ( int i = 1; i <= 52; i++ ) present [i] = i;

		char input [50];

		while ( gets (input) && strlen (input) ) {
			int num = atoi (input);
			int next [52 + 3];
			
			for ( int i = 1; i <= 52; i++ )
				next [i] = present [shuffles [num] [i]];

			for ( int i = 1; i <= 52; i++ ) present [i] = next [i];
		}

		if ( blank ) printf ("\n");
		blank = true;

		for ( int i = 1; i <= 52; i++ ) 
			cout << cardName [present [i]] << endl;
	}

	return 0;
}

// @END_OF_SOURCE_CODE

One thought on “UVa : 10205 ( Stack ’em Up)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s