Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stackEmUp;
- import java.util.ArrayList;
- import java.util.Scanner;
- //http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=30&problem=1146
- public class StackEmUp
- {
- public static void main(String[] args)
- {
- ArrayList<ArrayList<Integer>> shuffles= new ArrayList<ArrayList<Integer>>();
- ArrayList<Integer> shuffleSequence = new ArrayList<Integer>();
- String[] currentDeck = new String[52];
- int shufflesCount;
- String dealerShuffle;
- Scanner in = new Scanner(System.in);
- int cases = in.nextInt();
- in.nextLine();
- in.nextLine();
- for (int i = 0; i < cases; i++)
- {
- shufflesCount = in.nextInt();
- in.nextLine();
- for (int j = 0; j < shufflesCount; j++)
- {
- shuffles.add(new ArrayList<Integer>());
- for (int k = 0; k < 52; k++) shuffles.get(j).add(in.nextInt());
- }
- in.nextLine();
- while (in.hasNext())
- {
- dealerShuffle = in.nextLine();
- if(dealerShuffle.equals("")) break;
- shuffleSequence.add(Integer.parseInt(dealerShuffle));
- }
- orderDeck(currentDeck);
- for (int j = 0; j < shuffleSequence.size(); j++)
- {
- currentDeck = doShuffle(shuffles.get(shuffleSequence.get(j)-1),currentDeck);
- }
- for (int j = 0; j < currentDeck.length; j++)
- {
- System.out.println(currentDeck[j]);
- }
- shuffleSequence.clear();
- shuffles.clear();
- if(i!=cases-1) System.out.println();
- }
- }
- private static String[] doShuffle(ArrayList<Integer> shuffle,String[] currentDeck)
- {
- String[] nextDeck = new String[52];
- for (int i = 0; i < 52; i++)
- {
- nextDeck[i] = currentDeck[shuffle.get(i)-1];
- }
- return nextDeck;
- }
- private static void orderDeck(String[] deck)
- {
- int i = 0;
- for (; i < 9; i++) deck[i] = (i+2) +" of Clubs";
- deck[9] = "Jack of Clubs";
- deck[10] = "Queen of Clubs";
- deck[11] = "King of Clubs";
- deck[12] = "Ace of Clubs";
- for (i=13; i < 22; i++) deck[i] = (i-11) +" of Diamonds";
- deck[22] = "Jack of Diamonds";
- deck[23] = "Queen of Diamonds";
- deck[24] = "King of Diamonds";
- deck[25] = "Ace of Diamonds";
- for (i=26; i < 35; i++) deck[i] = (i-24) +" of Hearts";
- deck[35] = "Jack of Hearts";
- deck[36] = "Queen of Hearts";
- deck[37] = "King of Hearts";
- deck[38] = "Ace of Hearts";
- for (i=39; i < 48; i++) deck[i] = (i-37) +" of Spades";
- deck[48] = "Jack of Spades";
- deck[49] = "Queen of Spades";
- deck[50] = "King of Spades";
- deck[51] = "Ace of Spades";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement