Page 4 of 5

Re: 10205 - Stack 'em Up

Posted: Mon Dec 22, 2008 9:26 am
by wjomlex
I'm getting WA, and I've tested it with quite a few different cases. I imagine it's a problem with tokenizing the input. If anyone's got a thought, or a test case that it fails on, please post it ^_^

Code: Select all

import java.util.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);

		int t = scan.nextInt();

		for(int ca=0;ca < t;ca++)
		{
			int n = scan.nextInt();

			int[][] s = new int[n][52]; //shuffle array

			for(int i=0;i < n;i++)
			{
				for(int j=0;j < 52;j++)
					s[i][j] = scan.nextInt();
			}

			scan.nextLine(); //throw away the blank line

			int[] a = new int[52]; //deck array

			for(int i=0;i < 52;i++)
				a[i] = i;

			//process
			while(scan.hasNextLine())
			{
				String str = scan.nextLine();

				if(str.equals(""))
					break;

				int k = Integer.parseInt(str) - 1;
				
				int[] tmp = new int[52];

				for(int i=0;i < 52;i++)
				{
					tmp[s[k][i]-1] = a[i];
				}

				a = tmp;
			}

			//output
			for(int i=0;i < 52;i++)
			{
				int rank = a[i] % 13;

				if(rank < 9)
					System.out.print(rank+2);
				else
					switch(rank)
					{
						case 9:
							System.out.print("Jack");
							break;
						case 10:
							System.out.print("Queen");
							break;
						case 11:
							System.out.print("King");
							break;
						case 12:
							System.out.print("Ace");
							break;
					}
				
				System.out.print(" of ");

				switch(a[i] / 13)
				{
					case 0:
						System.out.println("Clubs");
						break;
					case 1:
						System.out.println("Diamonds");
						break;
					case 2:
						System.out.println("Hearts");
						break;
					case 3:
						System.out.println("Spades");
						break;
				}
			}

			if(ca < t-1)
				System.out.println();
		}
	}
}

Re: 10205 - Stack 'em Up

Posted: Fri Apr 09, 2010 10:09 pm
by tristanx9
I have tested all cases I could found on web. my code works in all of them. I really don't have a clue about what is happening. Someone can please help me.

Code: Select all

import java.io.*;

class Main {

    String valores[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
    String naipes[] = {"Clubs", "Diamonds", "Hearts", "Spades"};
    String embaralhada[][];
    int baralho[];
    int baralho_aux[];

    public void Begin() throws IOException{

       int rep, emb, cur;
       String [] aux;
       BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
      
       rep = Integer.parseInt(entrada.readLine());
       entrada.readLine();

        for(int i=0;i<rep;i++){
            baralho = new int[52];

            /* initialize deck */
            for(int j=0;j<52;j++){
                baralho[j] = j;
            }

            emb = Integer.parseInt(entrada.readLine());
            embaralhada = new String[emb][52];

            /* read list of known shuffles */
            for(int j=0;j<emb;j++){
                embaralhada[j] =  entrada.readLine().split("\\s");
            }

            /* shuffle deck */
            for(int j=0;j<emb;j++){
                cur = Integer.parseInt(entrada.readLine());
                baralho_aux = new int[52];
                for(int k=0;k<52;k++){
                    baralho_aux[k] = baralho[Integer.parseInt(embaralhada[cur-1][k])-1];
                }
                for(int k=0;k<52;k++){
                    baralho[k] = baralho_aux[k];
                }
            }

            /* print deck */
            for(int j=0;j<52;j++){
                System.out.println(valores[baralho[j]%13]+" of "+naipes[baralho[j]/13]);
            }

            if(i<rep-1) System.out.println();
            entrada.readLine();
        }
   }

    public static void main(String[] args) throws IOException {
        Main programa = new Main();
        programa.Begin();
    }
}

Input:

Code: Select all

2

100
48 1 19 6 3 46 39 21 22 31 18 44 27 4 33 52 49 38 47 25 17 5 10 29 43 37 11 36 30 20 34 7 16 12 28 32 50 42 24 51 9 45 14 8 23 35 26 40 2 13 15 41
40 5 52 30 6 7 47 23 8 42 37 12 15 14 28 3 34 18 41 38 17 10 4 32 43 11 50 22 20 26 19 29 13 16 21 1 39 36 46 27 51 49 2 45 35 25 9 31 48 33 44 24
39 48 2 35 22 9 49 13 15 37 43 46 4 29 30 24 10 21 20 26 19 52 33 36 42 32 40 6 7 27 38 1 11 5 16 17 12 34 3 14 25 41 31 18 47 23 51 8 50 45 44 28
3 8 13 32 28 22 43 21 40 23 10 26 25 27 29 34 17 30 12 5 48 45 44 37 33 2 7 47 4 36 42 11 1 49 51 24 15 35 16 50 52 18 6 38 14 20 41 19 31 39 9 46
17 3 41 10 14 16 52 8 39 32 25 1 23 12 19 30 29 22 42 36 35 48 43 46 26 47 37 4 50 44 31 28 33 15 2 24 7 6 13 49 21 40 45 5 51 11 20 9 34 38 27 18
10 8 17 27 43 39 18 42 15 19 33 21 2 11 14 26 3 4 40 16 48 45 30 22 13 51 35 23 34 25 50 12 6 7 28 41 46 47 1 38 20 49 29 32 44 36 24 9 31 37 52 5
29 5 7 16 9 27 24 8 23 4 22 20 21 48 44 34 19 2 14 17 45 40 28 18 51 47 52 15 31 33 42 38 41 30 11 50 6 49 32 26 25 12 35 10 36 37 39 3 46 43 13 1
8 30 52 6 29 13 4 2 10 5 38 41 18 46 17 43 32 49 26 34 16 48 15 20 39 28 7 22 45 27 51 19 50 42 31 33 11 21 24 25 3 9 37 47 1 40 14 36 35 23 12 44
2 38 17 42 33 24 5 47 34 35 16 44 20 18 15 45 43 28 32 52 29 26 30 7 25 6 1 50 22 41 4 13 27 8 23 14 36 9 21 51 11 46 37 10 31 49 19 3 40 12 39 48
20 39 41 44 52 14 22 19 3 7 24 36 31 17 51 16 42 2 10 4 5 25 40 45 18 47 49 33 9 34 35 37 50 43 6 13 30 46 28 38 8 11 21 1 23 27 26 15 32 12 48 29
2 39 49 19 45 30 41 15 40 33 18 50 11 1 20 4 48 5 42 14 22 36 9 35 16 38 23 52 17 13 47 8 46 3 6 32 25 12 26 37 24 34 51 27 44 31 7 29 10 28 21 43
38 25 41 5 10 7 43 14 40 4 28 6 18 24 36 13 45 22 20 30 34 17 23 19 16 42 26 39 12 33 27 37 51 8 47 11 46 21 3 29 1 31 50 15 35 44 49 52 9 48 2 32
18 20 46 41 34 35 43 9 30 25 4 8 36 48 49 37 51 11 47 14 45 26 15 29 27 44 28 39 31 19 6 13 50 16 38 10 12 24 21 23 7 5 33 42 40 32 2 17 3 52 22 1
6 20 42 17 3 9 31 47 26 16 4 46 15 27 51 25 43 12 5 36 50 10 18 34 29 52 39 33 19 28 41 32 35 44 49 14 22 1 37 40 23 13 48 2 30 7 21 8 45 38 24 11
50 4 26 38 8 7 1 28 49 20 42 14 6 27 47 29 32 9 44 16 17 30 3 13 41 52 46 51 36 31 33 2 19 40 22 15 24 10 23 25 45 37 43 5 39 48 12 18 35 34 11 21
22 37 1 26 42 33 18 2 11 41 29 15 40 3 31 24 34 36 9 52 32 39 43 8 4 35 46 21 5 25 7 47 13 28 17 45 16 44 12 48 19 20 30 50 10 38 49 27 51 14 23 6
42 33 20 26 21 7 29 36 23 11 3 50 22 19 16 37 43 25 27 10 48 18 6 35 46 39 24 15 45 28 49 8 52 1 41 12 38 30 40 9 14 51 32 5 31 34 17 2 47 13 44 4
51 14 29 44 6 10 31 24 27 2 26 21 11 45 46 16 34 13 15 4 37 17 39 8 18 52 42 38 9 7 22 50 32 49 43 25 35 3 40 1 41 19 33 12 28 30 48 23 20 5 36 47
35 30 50 15 28 29 10 11 46 27 20 43 41 24 51 38 1 8 48 47 25 33 40 18 2 5 52 4 6 37 23 36 16 13 26 17 49 22 45 42 12 3 14 31 19 32 21 9 44 39 34 7
40 20 21 50 27 4 2 35 13 19 3 38 26 17 28 45 42 31 22 39 16 10 23 37 30 46 33 9 24 29 52 34 51 32 1 18 48 49 25 14 44 11 6 43 7 41 5 12 47 36 15 8
3 11 12 2 23 34 18 20 4 48 25 30 43 44 37 38 51 31 33 14 24 5 8 39 9 27 13 15 22 10 36 50 41 49 47 35 19 40 46 1 6 21 45 17 28 7 42 32 26 16 29 52
26 50 4 6 20 21 36 49 29 11 33 32 17 7 15 16 3 37 22 30 38 52 48 35 9 31 5 24 39 44 25 13 43 34 47 19 8 42 23 28 41 1 12 45 51 40 10 46 14 2 18 27
11 5 24 32 27 44 43 37 40 3 20 13 28 26 30 17 16 29 25 48 46 45 49 1 22 38 41 34 36 47 33 8 14 23 35 10 6 4 2 15 21 39 7 52 12 19 42 51 31 18 50 9
43 21 17 12 41 24 7 22 13 4 46 11 50 3 32 52 49 15 23 51 5 27 36 20 28 1 37 6 14 2 33 40 48 44 47 18 31 8 25 29 10 39 42 16 38 9 34 30 26 35 19 45
33 10 6 52 29 12 16 43 14 27 21 28 49 22 15 48 32 24 7 5 1 35 51 25 17 3 42 18 23 19 41 31 26 9 4 30 2 45 44 37 13 11 20 39 34 38 50 36 46 40 47 8
27 2 34 19 9 29 40 31 16 50 13 33 18 7 8 38 12 41 24 37 1 4 26 36 11 49 14 22 25 3 23 48 5 46 39 10 35 6 20 51 30 43 42 52 45 28 17 32 47 15 44 21
24 41 22 16 37 35 46 19 9 43 8 45 52 6 15 21 30 44 27 51 25 39 14 29 48 38 12 32 18 20 7 50 40 3 10 34 33 1 47 42 11 31 23 49 5 28 36 4 2 17 13 26
15 1 22 45 29 19 52 51 16 14 26 20 13 5 12 10 36 34 46 37 11 8 41 6 9 39 25 28 50 30 7 2 49 35 27 47 17 31 38 23 42 40 3 33 4 43 18 48 32 44 24 21
43 9 8 10 32 36 1 4 42 3 27 19 7 18 44 12 37 11 41 33 28 5 26 40 52 14 49 6 51 47 13 20 48 39 23 29 50 17 46 15 30 45 31 34 38 35 2 25 22 16 21 24
20 29 50 21 22 46 25 48 40 27 16 18 4 39 11 23 8 19 15 37 38 10 28 30 31 2 36 26 13 12 9 52 49 3 5 6 47 35 41 7 43 44 32 24 51 42 17 1 14 33 34 45
46 8 32 28 2 3 22 9 39 52 12 43 21 16 33 15 41 45 13 44 23 25 24 38 47 34 29 26 31 40 35 17 27 14 20 5 1 36 19 42 51 50 49 7 30 11 48 37 10 4 18 6
2 25 27 44 40 15 49 37 16 50 42 26 28 21 36 52 39 5 38 11 13 51 30 33 7 19 29 24 32 3 17 12 34 20 18 6 31 22 10 47 45 41 35 46 43 1 9 8 48 4 23 14
11 13 24 51 21 39 15 38 45 20 33 2 25 52 5 1 46 12 34 41 42 35 44 31 49 43 27 37 8 40 23 48 4 9 32 16 30 18 26 19 7 36 3 6 14 10 17 22 50 28 29 47
7 8 12 50 13 52 6 15 35 18 41 21 10 31 22 28 19 11 43 44 39 23 9 17 25 30 3 42 49 47 32 14 24 45 40 36 48 2 51 46 1 27 33 20 34 4 37 26 29 5 38 16
40 46 24 38 4 36 29 22 35 10 2 14 37 19 13 3 45 7 43 50 52 23 11 32 41 51 6 34 1 31 30 21 48 33 20 27 26 39 28 18 8 16 25 17 5 47 15 9 12 44 49 42
19 6 25 20 34 44 26 10 11 21 24 16 39 13 5 8 22 29 32 46 28 48 40 43 12 41 36 9 23 14 38 51 47 35 33 30 52 49 45 4 27 17 2 42 7 18 3 37 15 1 50 31
34 39 36 4 21 8 44 14 29 12 25 1 22 37 32 28 42 41 26 40 30 23 13 17 46 19 24 5 9 3 2 7 35 15 20 11 18 50 45 51 6 10 49 27 16 31 48 52 43 38 33 47
18 47 12 39 31 30 16 40 23 46 38 19 45 3 33 37 20 1 51 32 14 6 8 43 13 24 2 4 9 25 41 34 42 35 28 48 5 7 27 21 52 10 44 50 15 36 22 49 17 11 29 26
27 10 9 38 20 50 8 47 26 21 45 44 18 4 23 2 11 33 19 5 35 24 39 29 30 7 3 28 37 25 6 46 41 34 43 1 49 52 17 51 16 22 15 13 31 12 36 32 42 14 48 40
33 13 48 12 11 17 15 28 14 32 19 3 30 36 39 2 22 4 24 50 44 40 45 31 1 8 46 49 35 43 6 41 16 25 38 10 42 34 21 7 9 5 23 47 26 52 18 29 27 51 20 37
31 2 45 33 16 41 4 20 15 19 38 40 52 37 6 24 1 51 18 29 14 8 32 34 28 36 46 7 12 26 35 23 47 30 21 13 9 10 50 17 5 3 22 49 48 25 39 42 43 11 27 44
2 13 28 18 3 22 19 23 12 47 1 11 10 8 6 43 17 4 15 14 34 24 21 5 46 27 38 30 40 26 52 35 48 36 7 45 42 39 29 37 49 33 44 41 32 25 16 50 20 51 9 31
30 9 29 7 13 22 21 42 40 20 37 6 16 10 51 33 46 44 1 28 52 15 25 8 11 24 31 38 41 32 14 34 3 2 27 4 17 19 49 36 45 26 5 12 43 48 18 35 50 23 47 39
2 51 10 7 46 16 13 30 38 25 33 12 4 6 39 44 9 3 22 1 8 47 48 31 42 49 5 15 19 35 11 14 21 24 27 37 52 34 20 32 17 43 23 45 29 36 41 40 50 26 28 18
8 28 3 51 36 23 25 29 44 26 18 4 47 6 1 46 12 21 45 17 42 40 50 22 15 39 7 32 31 24 49 11 5 13 9 48 27 20 19 2 10 30 35 16 41 38 34 43 14 33 37 52
9 10 17 2 4 18 11 30 24 3 13 37 34 20 32 45 14 31 52 36 27 15 44 21 51 1 38 41 23 7 39 29 43 33 49 22 5 50 8 12 28 19 40 25 16 6 47 35 26 46 42 48
35 44 8 47 14 17 36 33 19 41 40 23 31 21 51 25 18 38 4 46 10 29 43 34 50 3 5 13 20 9 1 11 30 39 22 12 45 49 6 24 52 37 48 27 7 26 2 16 32 28 42 15
21 31 36 19 40 10 18 2 30 23 5 25 12 11 28 17 4 44 27 14 26 51 33 9 48 8 35 34 1 42 3 38 45 47 39 24 22 37 32 6 29 52 46 41 7 15 20 49 50 43 16 13
28 31 25 40 42 23 50 30 10 38 16 36 6 43 51 41 21 4 13 49 33 32 12 26 8 35 19 39 52 15 27 9 46 37 24 2 1 18 44 7 29 5 22 48 3 14 11 20 47 45 34 17
43 34 14 16 3 5 2 44 49 47 32 42 39 20 9 31 23 26 21 7 48 52 37 29 18 15 40 28 22 25 6 12 1 35 11 46 27 30 19 13 50 51 8 10 36 45 17 4 24 33 38 41
2 23 19 37 17 25 24 18 20 31 9 50 5 43 32 33 30 40 46 36 7 28 41 27 14 6 29 16 47 22 45 3 49 11 10 35 21 26 13 42 15 52 1 12 38 48 34 44 8 4 51 39
30 51 42 44 9 26 24 35 23 3 6 4 41 25 7 1 48 21 19 18 13 40 16 14 29 32 17 15 37 20 5 52 2 46 36 28 11 8 45 43 22 39 47 38 27 33 31 49 50 10 34 12
4 27 46 30 36 37 11 45 15 5 28 50 16 39 6 20 19 14 49 43 12 51 3 7 32 9 34 23 10 48 2 52 8 33 40 13 41 31 29 17 21 44 35 1 26 22 24 18 25 38 42 47
13 51 8 19 37 46 12 17 40 18 4 21 50 30 49 44 35 36 23 34 52 45 25 3 42 7 38 9 11 10 39 2 26 20 15 27 5 24 29 41 6 47 1 14 33 28 32 48 43 22 16 31
46 33 34 31 39 50 8 35 32 21 26 52 17 20 44 10 48 24 25 14 13 7 41 11 28 47 38 2 37 36 1 9 43 16 19 6 3 49 4 40 30 5 18 45 51 42 22 27 12 15 29 23
41 12 34 37 19 30 22 1 40 49 52 14 45 20 26 21 44 31 9 48 35 5 6 3 33 18 36 24 28 32 16 2 51 50 38 46 4 42 17 23 8 11 7 39 13 10 29 25 47 27 43 15
7 32 28 9 38 11 35 43 5 40 24 8 16 20 10 52 30 26 17 31 42 46 25 41 14 2 37 49 1 39 48 12 6 22 47 27 34 3 23 29 19 13 36 18 45 15 4 44 51 21 33 50
3 26 6 9 24 11 50 21 7 39 43 44 27 41 16 38 23 35 48 30 12 18 14 20 36 46 1 10 25 31 51 40 28 47 32 15 33 45 42 4 17 22 8 49 5 29 2 19 13 34 37 52
8 16 9 47 6 17 45 7 52 22 11 35 30 49 32 29 41 24 25 4 46 42 27 39 23 28 5 38 13 37 43 34 26 2 50 51 48 31 36 19 14 21 20 1 12 10 40 44 33 18 3 15
32 19 42 43 26 48 33 34 50 30 5 16 46 20 18 23 41 12 31 38 2 27 10 39 3 1 7 8 25 28 35 37 24 17 44 29 36 45 21 51 22 6 11 4 40 13 52 49 9 47 14 15
3 31 15 26 49 11 14 43 51 25 18 2 34 17 30 22 20 4 5 29 24 41 27 35 9 23 47 12 50 37 1 52 8 44 28 36 38 33 10 46 6 40 7 16 21 13 19 42 48 32 45 39
15 20 39 11 17 41 14 7 12 38 16 33 24 50 2 13 22 10 25 29 46 49 51 26 47 34 35 52 1 21 3 30 4 18 28 36 40 37 44 43 9 32 5 27 42 23 48 8 31 6 19 45
27 36 20 13 2 8 30 42 10 22 49 21 25 37 18 41 26 15 17 16 12 24 38 39 4 23 9 48 7 19 52 3 47 32 34 33 29 1 6 51 44 31 28 45 5 50 35 11 14 46 40 43
49 44 12 37 28 51 5 15 2 46 17 32 22 27 25 47 48 14 29 30 31 23 11 38 7 42 41 19 26 34 39 24 43 16 21 50 3 18 13 36 9 45 10 35 40 8 4 6 20 1 33 52
5 15 2 40 21 29 32 39 27 10 6 20 12 34 52 42 16 24 48 35 7 1 36 45 4 43 11 33 19 41 22 30 50 18 38 47 31 25 44 28 37 49 46 14 3 51 13 9 26 23 17 8
21 17 44 23 20 18 22 11 47 8 49 38 37 39 28 5 50 1 33 24 34 32 10 16 26 48 2 43 31 19 4 52 15 30 3 36 51 45 40 46 7 42 6 29 13 27 14 41 9 35 25 12
24 45 14 9 16 25 30 23 50 44 3 21 1 31 12 26 51 52 33 6 48 39 19 41 8 22 7 18 43 5 20 34 13 46 36 38 4 42 47 15 11 28 32 35 27 10 37 49 17 40 29 2
3 32 6 33 7 8 9 31 11 4 35 30 2 40 17 46 25 42 19 24 13 38 26 28 29 41 36 16 12 49 22 27 10 1 20 48 47 15 39 21 18 45 23 51 37 50 43 44 52 5 34 14
10 27 3 5 21 7 40 33 20 29 1 23 9 2 14 32 31 45 47 6 50 18 8 41 36 25 37 4 46 15 12 51 48 49 28 26 44 16 19 11 38 30 24 39 13 43 17 35 42 22 34 52
46 14 25 44 4 7 8 9 29 33 38 28 36 42 31 12 48 50 51 47 19 22 16 35 2 24 43 17 40 3 20 39 45 1 34 5 10 18 26 23 41 15 30 27 32 52 11 37 21 13 6 49
27 33 11 46 39 29 9 12 43 16 25 28 21 31 19 18 17 48 20 42 30 36 45 38 26 32 37 13 24 15 40 41 8 14 10 6 7 44 50 22 52 35 51 2 5 23 4 49 47 1 34 3
18 28 42 8 16 5 41 34 40 11 46 20 23 17 12 1 45 50 32 4 7 33 36 14 27 35 37 48 30 3 29 9 31 43 21 13 51 49 19 26 47 38 44 6 24 15 2 22 10 39 25 52
39 10 23 43 36 9 6 52 51 33 25 48 44 4 18 28 38 21 29 22 45 2 15 37 46 47 30 26 3 16 13 1 50 20 11 31 34 49 7 32 19 41 14 40 12 8 42 27 5 24 35 17
36 4 29 49 42 24 12 18 35 48 27 25 21 33 16 44 39 17 30 9 8 14 6 13 41 40 7 10 34 47 19 15 46 37 50 11 22 5 31 26 20 3 32 52 51 38 43 23 45 2 28 1
2 44 33 3 49 9 31 22 38 5 11 28 25 47 27 40 18 15 17 10 26 45 30 16 24 50 7 4 23 41 36 34 29 35 21 52 1 20 8 13 32 19 6 37 51 46 42 14 48 39 43 12
18 28 32 10 43 27 20 19 44 2 22 36 39 49 12 21 30 29 24 14 11 51 15 4 3 37 31 33 1 52 26 50 23 17 40 45 41 38 34 48 46 5 9 42 8 13 16 6 25 7 35 47
5 42 35 9 11 38 12 27 23 17 18 26 46 45 43 16 36 41 29 7 13 44 20 37 50 21 52 31 28 8 34 48 51 10 49 47 4 3 15 25 22 6 1 14 39 19 32 40 33 2 30 24
11 26 4 24 1 17 7 33 16 28 19 41 36 25 13 6 42 37 14 38 35 9 3 2 34 43 29 30 5 49 21 23 50 27 45 47 20 52 40 8 39 12 46 51 18 48 10 22 15 31 32 44
16 14 9 49 41 15 11 1 3 2 36 32 52 28 5 27 6 21 31 38 4 13 42 43 18 45 22 25 8 19 33 50 7 23 46 39 40 47 35 12 10 26 20 17 34 29 30 51 44 48 24 37
50 30 25 5 37 24 15 44 46 19 6 2 16 22 27 26 49 21 47 9 13 10 48 28 23 33 42 52 12 4 39 1 51 29 40 7 17 34 14 3 43 32 38 31 20 11 36 41 8 45 35 18
44 27 43 47 30 25 16 22 35 40 15 49 42 45 50 18 10 1 36 34 28 2 24 9 8 21 12 37 51 26 52 38 4 3 39 41 29 5 48 19 32 14 23 17 6 33 11 20 46 7 31 13
29 52 11 13 21 17 28 1 2 42 16 37 35 51 38 7 8 32 48 34 33 15 45 9 19 43 39 31 18 22 25 20 26 36 10 27 24 30 6 14 44 46 23 41 49 3 4 12 5 40 50 47
38 10 39 52 17 30 3 28 16 14 50 25 46 7 37 9 43 26 47 15 22 21 5 33 18 34 42 36 8 24 32 27 41 49 12 45 4 6 48 2 35 11 20 51 23 44 19 1 13 31 40 29
29 3 20 11 39 22 13 37 49 30 16 6 17 33 25 14 5 10 38 8 42 9 27 32 28 40 23 26 48 52 2 18 36 41 24 51 7 4 45 35 34 47 31 19 21 50 1 44 46 43 15 12
38 52 20 40 17 11 1 46 31 45 14 15 19 33 44 23 29 37 28 6 41 39 9 5 48 51 21 32 35 22 3 24 7 49 36 16 47 27 13 34 42 8 12 10 26 50 30 25 2 43 4 18
11 9 43 20 41 8 49 15 3 51 7 16 18 45 50 27 25 17 6 21 14 13 33 34 19 48 2 44 40 37 22 38 46 5 28 1 52 4 47 31 26 39 24 23 36 35 12 42 30 29 32 10
1 26 38 31 6 23 11 32 49 25 10 33 43 21 47 52 20 36 2 12 14 16 35 40 15 8 7 46 4 51 9 5 18 42 50 24 30 13 44 27 39 45 17 41 3 48 37 29 34 28 22 19
32 14 23 41 6 28 25 17 43 19 12 2 30 18 15 46 27 26 16 8 49 44 34 45 47 4 35 10 40 48 20 33 36 5 21 7 51 13 42 50 29 52 38 11 31 37 3 39 9 24 22 1
36 19 30 15 10 21 13 38 16 28 46 24 4 44 35 40 43 51 20 18 5 6 7 22 31 42 25 8 14 37 29 17 1 12 26 41 32 45 2 11 23 3 27 39 34 47 9 49 50 48 33 52
26 12 21 4 8 39 27 17 22 45 34 24 16 38 52 6 11 13 44 30 23 25 32 50 48 28 42 40 43 2 49 36 29 9 47 19 46 14 10 41 37 18 31 15 5 33 1 3 51 35 20 7
14 15 41 29 19 6 18 7 4 50 37 31 30 38 39 3 10 22 32 13 11 49 9 52 43 16 24 20 45 12 26 23 17 27 42 44 36 25 46 47 28 48 40 8 35 51 33 21 2 5 34 1
19 8 18 40 10 21 46 11 45 49 30 25 47 41 44 28 27 20 52 14 50 26 3 5 35 6 4 33 13 37 39 29 43 22 2 31 36 24 1 9 42 38 17 51 15 12 23 16 32 34 48 7
31 24 19 3 41 32 47 28 45 5 36 34 11 23 8 43 21 22 26 35 15 6 2 30 38 17 18 12 52 46 20 39 7 13 40 14 1 25 9 49 10 33 37 16 50 48 27 29 51 44 42 4
27 32 51 7 46 3 36 45 8 37 29 19 41 49 47 11 10 25 26 38 21 24 40 20 48 43 14 9 15 18 33 28 42 13 1 6 16 39 31 44 35 50 4 12 5 23 17 22 52 34 30 2
33 9 1 27 30 23 17 2 14 18 15 29 41 32 20 50 39 44 34 36 37 3 11 28 24 12 46 7 31 5 19 49 35 26 40 22 42 13 47 38 16 51 52 25 21 43 45 48 8 10 6 4
35 28 50 9 12 7 27 48 1 17 37 39 46 19 29 38 3 45 31 6 43 26 44 32 49 5 14 23 34 21 33 11 36 42 30 40 13 41 16 4 25 2 52 18 8 22 15 51 47 24 20 10
4 1 23 50 19 27 11 37 34 43 9 20 42 40 26 29 32 14 12 35 8 24 25 28 16 5 7 46 10 39 13 31 2 36 38 52 33 47 22 48 6 15 51 18 3 30 49 21 44 45 41 17
25 18 19 28 35 9 30 13 24 8 33 32 11 34 5 10 26 45 27 31 43 36 47 14 21 3 49 22 52 6 48 51 2 12 4 7 44 1 42 15 39 50 37 23 29 17 38 16 41 46 20 40
22 21 44 7 30 36 49 2 50 32 17 35 11 19 10 1 23 40 18 14 42 51 45 27 48 34 46 41 47 28 43 39 33 20 31 5 24 25 37 26 4 8 12 38 9 3 13 52 29 15 16 6
1 11 12 22 6 50 49 26 30 16 40 9 48 33 52 15 23 25 41 8 24 18 7 10 42 28 47 5 43 19 46 34 36 13 39 35 29 20 3 4 27 44 31 21 45 51 32 2 17 38 14 37
25
88
47
58
29
70
98
55
68
68
12
89
23
12
10
84
48
8
83
14
5
23
95
21
2
85
79
38
73
54
93
97
42
39
55
22
60
52
28
28
71
39
68
94
3
29
29
50
36
11
16
93
85
10
65
86
47
44
75
19
49
67
16
42
58
22
63
69
25
42
96
96
81
16
41
83
44
69
84
32
32
99
24
68
61
40
54
7
83
28
25
32
47
92
25
4
65
88
24
90

2
2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 52 51
52 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 1
1
2

Output:

Code: Select all

3 of Spades
9 of Clubs
Ace of Spades
9 of Diamonds
10 of Spades
King of Diamonds
5 of Clubs
5 of Diamonds
6 of Clubs
6 of Hearts
5 of Hearts
3 of Clubs
4 of Hearts
7 of Clubs
Queen of Hearts
Jack of Diamonds
5 of Spades
8 of Clubs
2 of Diamonds
7 of Diamonds
7 of Hearts
4 of Spades
2 of Spades
Queen of Clubs
4 of Clubs
Jack of Spades
Queen of Spades
King of Hearts
2 of Hearts
7 of Spades
Ace of Hearts
6 of Spades
8 of Diamonds
4 of Diamonds
King of Spades
6 of Diamonds
8 of Hearts
9 of Hearts
10 of Clubs
10 of Diamonds
Ace of Diamonds
2 of Clubs
King of Clubs
Jack of Hearts
9 of Spades
3 of Hearts
3 of Diamonds
Ace of Clubs
10 of Hearts
8 of Spades
Jack of Clubs
Queen of Diamonds

King of Spades
2 of Clubs
4 of Clubs
5 of Clubs
6 of Clubs
7 of Clubs
8 of Clubs
9 of Clubs
10 of Clubs
Jack of Clubs
Queen of Clubs
King of Clubs
Ace of Clubs
2 of Diamonds
3 of Diamonds
4 of Diamonds
5 of Diamonds
6 of Diamonds
7 of Diamonds
8 of Diamonds
9 of Diamonds
10 of Diamonds
Jack of Diamonds
Queen of Diamonds
King of Diamonds
Ace of Diamonds
2 of Hearts
3 of Hearts
4 of Hearts
5 of Hearts
6 of Hearts
7 of Hearts
8 of Hearts
9 of Hearts
10 of Hearts
Jack of Hearts
Queen of Hearts
King of Hearts
Ace of Hearts
2 of Spades
3 of Spades
4 of Spades
5 of Spades
6 of Spades
7 of Spades
8 of Spades
9 of Spades
10 of Spades
Jack of Spades
Queen of Spades
Ace of Spades
3 of Clubs

Re: 10205 - Stack 'em Up

Posted: Sun Apr 11, 2010 12:58 am
by tristanx9
I basically have done a identical code in c++ and as I suspected it was ACC, but I tried every modification in I/O to find the responsible but got nothing my c++ code is here. Someone can solve the mystery?

Code: Select all


#include <iostream>

using namespace std;

char valores[13][9] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
char naipes[4][9] = {"Clubs", "Diamonds", "Hearts", "Spades"};
int embaralhada[100][52];
int baralho[52];


/* main */
int main (int argc, const char *argv[]) {
	int rep;
	int emb;
	int cur;
		
	cin >> rep;
		
	for (int i=0; i<rep; i++) {	
		cin >> emb;
			
		/* initialize baralho */
		for (int j=0; j<52; j++) {
			baralho[j] = j;
		}
		
		/* read list of known embaralhada */
		
		for(int j=0; j<emb; j++) {
			for (int k=0; k<52; k++) {
				cin >> embaralhada[j][k];
			}
		}
		
		/* shuffle baralho */
		for (int j=0; j<emb; j++) {
			cin >> cur;
			

			int tmpbaralho[52];
			for (int k=0; k<52; k++) {
				tmpbaralho[k] = baralho[embaralhada[cur - 1][k] - 1];
			}
			for (int k=0; k<52;k++) {
				baralho[k] = tmpbaralho[k];
			}
		}

		/* print baralho */
		for (int k=0; k<52; k++) {
			cout << valores[baralho[k] % 13] << " of " << naipes[baralho[k] / 13] << endl;
		}
		if (i < (rep - 1)) {
			cout << endl;
		}
	}
	
}


Re: 10205 - Stack 'em Up

Posted: Thu Mar 08, 2012 6:17 pm
by Sawon90
I am just helpless...... I got many times wrong answer,, Please someone help me. Or give me some critical input and output, My code is.....
#include<stdio.h>
#include<string.h>
char car[60][50]={"","2 of Clubs","3 of Clubs","4 of Clubs","5 of Clubs","6 of Clubs","7 of Clubs","8 of Clubs",
"9 of Clubs","10 of Clubs","Jack of Clubs","Queen of Clubs","King of Clubs","Ace of Clubs",
"2 of Diamonds","3 of Diamonds","4 of Diamonds","5 of Diamonds","6 of Diamonds","7 of Diamonds",
"8 of Diamonds","9 of Diamonds","10 of Diamonds","Jack of Diamonds","Queen of Diamonds",
"King of Diamonds","Ace of Diamonds","2 of Hearts","3 of Hearts","4 of Hearts","5 of Hearts",
"6 of Hearts","7 of Hearts","8 of Hearts","9 of Hearts","10 of Hearts","Jack of Hearts",
"Queen of Hearts","King of Hearts","Ace of Hearts","2 of Spades","3 of Spades","4 of Spades",
"5 of Spades","6 of Spades","7 of Spades","8 of Spades","9 of Spades","10 of Spades",
"Jack of Spades","Queen of Spades","King of Spades","Ace of Spades"};
int main()
{
long i,k,a[110][60],T,n,p,nn;
scanf("%ld",&T);
while(T--)
{
for(i=1;i<=52;i++)
a[0]=i;
scanf("%ld",&n);
for(k=1;k<=n;k++)
{
for(i=1;i<=52;i++)
{
scanf("%ld",&p);
a[k][p]=a[k-1];
}
}
scanf("%ld",&nn);
while(nn--)
{
scanf("%ld",&k);
for(i=1;i<=52;i++)
printf("%s\n",car[a[k]]);
}
if(T)
printf("\n");
}
return 0;
}

Re: 10205 - Stack 'em Up

Posted: Fri Mar 09, 2012 12:45 am
by brianfry713
Input:

Code: Select all

1

2
2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 52 51
52 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 1
2
2
AC output:

Code: Select all

2 of Clubs
3 of Clubs
4 of Clubs
5 of Clubs
6 of Clubs
7 of Clubs
8 of Clubs
9 of Clubs
10 of Clubs
Jack of Clubs
Queen of Clubs
King of Clubs
Ace of Clubs
2 of Diamonds
3 of Diamonds
4 of Diamonds
5 of Diamonds
6 of Diamonds
7 of Diamonds
8 of Diamonds
9 of Diamonds
10 of Diamonds
Jack of Diamonds
Queen of Diamonds
King of Diamonds
Ace of Diamonds
2 of Hearts
3 of Hearts
4 of Hearts
5 of Hearts
6 of Hearts
7 of Hearts
8 of Hearts
9 of Hearts
10 of Hearts
Jack of Hearts
Queen of Hearts
King of Hearts
Ace of Hearts
2 of Spades
3 of Spades
4 of Spades
5 of Spades
6 of Spades
7 of Spades
8 of Spades
9 of Spades
10 of Spades
Jack of Spades
Queen of Spades
King of Spades
Ace of Spades

Re: 10205 - Stack 'em Up

Posted: Mon Mar 19, 2012 3:13 pm
by Sawon90
Many many thanks to brianfry713, actually I can't understand the problem statement clearly. Now I gor Accepted.

Re: 10205 - Stack 'em Up

Posted: Tue Feb 19, 2013 10:46 pm
by army007
I am getting WA.
I have tested it with sample I/O and other I/O from this forum, it works as expected.

But judge says my program is Wrong. Here is my code -

Code: Select all

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <valarray>
#include <functional>

using namespace std;

#define fo(i,j,n) for(i=j;i<n;++i)
#define Fo(i,j,n) for(i=n-1;i>=j;--i)
#define foo(i,j,v) fo(i,j,sz(v))
#define Foo(i,j,v) Fo(i,j,sz(v))
#define li(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
#define CLR(a,v) memset((a),(v),sizeof(a))
#define inf 1000000001
typedef long long Long;
//typedef __int64 Long;
#define pi (2*acos(0))
#define eps 1e-9

#define pb(x) push_back(x)
#define present(m,s) (m.find(s)!=m.end())

bool readn(int &n)	{ return scanf("%d",&n) == 1; }
//bool readl(Long &n)	{ return scanf("%I64d",&n) == 1; }
bool readd(double &n){ return scanf("%lf",&n) == 1; }

#define maxn 52+10
#define maxm 100+10

int A[maxm][maxn], B[3][maxn];

// a is the current suffle
// b is previous position of cards
// c will store the positions after current saffle

#define nCards 52
#define nSuits 4
#define cardsInSuit 13

string su[] = { "Clubs","Diamonds","Hearts","Spades" };
string val[] = {"2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace"};

inline
string suit(int n){
    return (su[n/cardsInSuit]);
}

inline
string value(int n){
    return (val[n%cardsInSuit]);
}

void doit(int a[], int b[], int c[]){
    int i;
    fo(i,1,nCards+1){
        c[a[i]] = b[i];
    }
}

void printres(int n){
    printf("%s of %s\n", value(n).c_str(), suit(n).c_str());
}

void print(int r[]){
    int i;
    fo(i,1,nCards+1){
        printres(r[i]-1);
    }
}

int main()
{
	#ifdef localhost
	freopen("G:\\test.in","r",stdin);
	freopen("G:\\test.out","w",stdout);
	#endif

	int n;
	string ss;

	int t,i,j;

	readn(t);
	while(t--){
        readn(n);
        fo(i,1,n+1){
            fo(j,1,nCards+1){
                readn(A[i][j]);
            }
        }

        i = 1;
        int k = 0;
        fo(i,1,nCards+1) { B[k][i] = i; }

        getline(cin,ss);

        while(getline(cin,ss)&& sz(ss)>0){
            int sf = atoi(ss.c_str());
            doit(A[sf],B[k],B[(k+1)%2]);
            k = (k+1)%2;
        }

        print(B[k]);
        if(t) printf("\n");
	}

	return 0;
}

Someone please help me.
Thanks in advance.

Re: 10205 - Stack 'em Up

Posted: Wed Feb 20, 2013 5:57 am
by lbv
army007 wrote:I am getting WA.
I have tested it with sample I/O and other I/O from this forum, it works as expected.

But judge says my program is Wrong.
You may try these cases:

Input

Code: Select all

2

5
2 49 3 34 10 23 12 45 6 7 46 31 15 18 52 37 27 14 19 39 22 5 51 30 29 11
42 38 44 9 13 40 21 32 41 16 36 47 4 43 35 24 20 26 1 8 48 25 50 17 28 33
43 6 7 45 30 33 5 16 22 21 15 36 26 29 11 25 20 42 52 47 38 41 18 3 40 2
28 39 8 49 32 10 50 51 17 37 19 27 31 48 35 23 4 1 34 12 44 24 46 14 9 13
2 11 48 5 24 19 43 12 23 27 49 33 52 13 29 35 18 45 6 34 28 9 10 17 26 50
36 41 22 51 25 7 8 37 47 21 15 38 1 30 16 40 32 4 31 46 14 20 3 42 39 44
20 25 47 12 6 52 11 10 5 50 45 49 39 30 31 2 22 24 18 43 13 17 48 42 16 19
41 28 15 9 21 23 27 35 1 46 44 36 51 26 40 14 37 32 29 4 8 7 33 34 38 3
3 49 36 16 52 28 19 8 9 22 37 32 25 30 11 2 31 15 4 47 51 6 21 38 24 42
5 33 50 14 41 29 26 12 13 27 35 48 7 1 46 10 20 39 18 40 44 23 45 34 17 43
4
4
2
5
3
4

2
9 2 32 40 29 22 38 47 10 16 24 33 43 31 11 23 1 37 12 30 36 50 25 6 19 14
27 48 46 52 17 35 4 5 42 26 18 8 51 21 15 39 13 45 41 3 49 20 44 7 28 34
17 24 21 45 3 42 10 9 50 35 4 43 52 49 6 32 19 13 28 29 22 27 48 37 39 31
8 40 26 30 5 2 12 34 38 15 44 47 16 36 1 46 7 25 51 41 23 18 11 14 20 33
1
1
2
Output

Code: Select all

5 of Clubs
8 of Clubs
2 of Hearts
4 of Diamonds
3 of Diamonds
Ace of Clubs
2 of Clubs
6 of Clubs
2 of Spades
Ace of Hearts
8 of Diamonds
7 of Hearts
7 of Spades
Queen of Hearts
9 of Clubs
Queen of Diamonds
10 of Diamonds
10 of Spades
5 of Hearts
Queen of Spades
Jack of Spades
4 of Hearts
Jack of Diamonds
6 of Spades
6 of Diamonds
King of Hearts
4 of Clubs
8 of Hearts
10 of Clubs
8 of Spades
10 of Hearts
Ace of Diamonds
3 of Hearts
5 of Spades
King of Clubs
Queen of Clubs
3 of Clubs
7 of Clubs
Ace of Spades
Jack of Hearts
6 of Hearts
7 of Diamonds
9 of Diamonds
9 of Spades
3 of Spades
King of Spades
9 of Hearts
Jack of Clubs
King of Diamonds
5 of Diamonds
2 of Diamonds
4 of Spades

10 of Clubs
10 of Diamonds
Ace of Diamonds
3 of Diamonds
10 of Hearts
King of Spades
Jack of Diamonds
4 of Diamonds
King of Hearts
Ace of Hearts
9 of Diamonds
5 of Spades
6 of Clubs
7 of Spades
Queen of Spades
4 of Spades
8 of Hearts
Ace of Clubs
8 of Diamonds
4 of Clubs
8 of Clubs
2 of Hearts
5 of Hearts
Queen of Hearts
3 of Hearts
2 of Clubs
Jack of Spades
Jack of Hearts
6 of Hearts
9 of Hearts
8 of Spades
3 of Clubs
5 of Clubs
4 of Hearts
9 of Spades
Queen of Diamonds
3 of Spades
6 of Spades
King of Diamonds
2 of Diamonds
Jack of Clubs
7 of Hearts
9 of Clubs
King of Clubs
10 of Spades
Queen of Clubs
7 of Diamonds
6 of Diamonds
7 of Clubs
5 of Diamonds
Ace of Spades
2 of Spades

Re: 10205 - Stack 'em Up

Posted: Tue Feb 18, 2014 4:38 am
by quique0194
I was getting wrong answer only because i put a blank line at the end of the output xD

Re: 10205 - Stack 'em Up

Posted: Sat Mar 22, 2014 3:35 pm
by uDebug
brianfry713, lbv,

Thanks for the great test cases.

Re: 10205 - Stack 'em Up WA

Posted: Mon Sep 15, 2014 2:14 am
by fresher96
:cry:
hey guys please help me
i have got about 8 WA
my code is very simple and it passed all the test cases in this forum
any help ??

Code: Select all

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;

//ofstream fout("out.txt");
int T;
int switches[101][53];

void print(string deck[])
{
	for(int i = 1; i<=52; i++)
	{
		if(deck[i][0] != 't' && deck[i][0] != 'j' && deck[i][0] != 'q' && deck[i][0] != 'k' && deck[i][0] != 'a')
			cout<<deck[i][0];
		else
		{
			if(deck[i][0] == 't')
				cout<<"10";
			else if(deck[i][0] == 'j')
				cout<<"Jack";
			else if(deck[i][0] == 'q')
				cout<<"Queen";
			else if(deck[i][0] == 'k')
				cout<<"King";
			else if(deck[i][0] == 'a')
				cout<<"Ace";
		}

		cout<<" of ";

		if(deck[i][1] == 'c')
			cout<<"Clubs";
		else if(deck[i][1] == 'd')
			cout<<"Diamonds";
		else if(deck[i][1] == 'h')
			cout<<"Hearts";
		else if(deck[i][1] == 's')
			cout<<"Spades";

		if(!(T==0 && i==52))
			cout<<endl;
	}
}

void make_switches(int k,string deck[])
{
	string new_deck[53];
	for(int i = 1; i<=52;i++)
	{
		int x = switches[k][i];
		new_deck[i] = deck[x];
	}
	for(int i = 1; i<=52;i++)
	{
		deck[i] = new_deck[i];
	}
}

int main()
{
	cin>>T;
	fflush(stdin);
	string line;
	getline(cin,line);
	while(T--)
	{
		string deck[] = { "","2c","3c","4c","5c","6c","7c","8c","9c","tc","jc","qc","kc","ac","2d","3d","4d","5d","6d","7d","8d","9d","td","jd","qd","kd","ad","2h","3h","4h","5h","6h","7h","8h","9h","th","jh","qh","kh","ah","2s","3s","4s","5s","6s","7s","8s","9s","ts","js","qs","ks","as"};
		int n;
		cin>>n;
		for(int j = 1; j<=n; j++)
		{
			for(int i = 1; i<=52; i++)
			{
				cin >> switches[j][i];
			}
		}
		int k;
		fflush(stdin);
		while(getline(cin,line) && line != "")
		{
			stringstream(line) >> k;
			make_switches(k , deck);
		}
		print(deck);

		if(T > 0)
			cout<<endl;
	}

	return 0;
}

Re: 10205 - Stack 'em Up

Posted: Mon Sep 15, 2014 9:08 pm
by brianfry713
Don't use fflush(stdin)

Re: 10205 - Stack 'em Up

Posted: Tue Sep 16, 2014 3:58 pm
by fresher96
brianfry713 wrote:Don't use fflush(stdin)
:D thanks a lot Master !
i'm sorry for that <dumb> mistake i almost cried

Re: 10205 - Stack 'em Up

Posted: Sat Nov 15, 2014 5:36 pm
by stevesJ03
Someone helps me please!! I got WA although I have test all test case in this topic.... This is my code:

Code: Select all

//Removed after AC. :D 

Re: 10205 - Stack 'em Up

Posted: Sat Nov 15, 2014 6:01 pm
by lighted
Try to copy/paste output format from sample or problem description. Or use file comparing tools to check correctness of output.

Sample Output

Code: Select all

Queen of Clubs
Your Output

Code: Select all

Qeen of Clubs