Advertisement
Guest User

StackemUp

a guest
Jul 11th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. package stackEmUp;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4. //http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=30&problem=1146
  5. public class StackEmUp
  6. {
  7. public static void main(String[] args)
  8. {
  9. ArrayList<ArrayList<Integer>> shuffles= new ArrayList<ArrayList<Integer>>();
  10. ArrayList<Integer> shuffleSequence = new ArrayList<Integer>();
  11. String[] currentDeck = new String[52];
  12. int shufflesCount;
  13. String dealerShuffle;
  14. Scanner in = new Scanner(System.in);
  15. int cases = in.nextInt();
  16. in.nextLine();
  17. in.nextLine();
  18. for (int i = 0; i < cases; i++)
  19. {
  20. shufflesCount = in.nextInt();
  21. in.nextLine();
  22. for (int j = 0; j < shufflesCount; j++)
  23. {
  24. shuffles.add(new ArrayList<Integer>());
  25. for (int k = 0; k < 52; k++) shuffles.get(j).add(in.nextInt());
  26. }
  27. in.nextLine();
  28. while (in.hasNext())
  29. {
  30. dealerShuffle = in.nextLine();
  31. if(dealerShuffle.equals("")) break;
  32. shuffleSequence.add(Integer.parseInt(dealerShuffle));
  33. }
  34. orderDeck(currentDeck);
  35.  
  36. for (int j = 0; j < shuffleSequence.size(); j++)
  37. {
  38. currentDeck = doShuffle(shuffles.get(shuffleSequence.get(j)-1),currentDeck);
  39. }
  40.  
  41. for (int j = 0; j < currentDeck.length; j++)
  42. {
  43. System.out.println(currentDeck[j]);
  44. }
  45.  
  46. shuffleSequence.clear();
  47. shuffles.clear();
  48. if(i!=cases-1) System.out.println();
  49. }
  50.  
  51. }
  52.  
  53. private static String[] doShuffle(ArrayList<Integer> shuffle,String[] currentDeck)
  54. {
  55. String[] nextDeck = new String[52];
  56. for (int i = 0; i < 52; i++)
  57. {
  58. nextDeck[i] = currentDeck[shuffle.get(i)-1];
  59. }
  60. return nextDeck;
  61. }
  62.  
  63. private static void orderDeck(String[] deck)
  64. {
  65. int i = 0;
  66. for (; i < 9; i++) deck[i] = (i+2) +" of Clubs";
  67. deck[9] = "Jack of Clubs";
  68. deck[10] = "Queen of Clubs";
  69. deck[11] = "King of Clubs";
  70. deck[12] = "Ace of Clubs";
  71. for (i=13; i < 22; i++) deck[i] = (i-11) +" of Diamonds";
  72. deck[22] = "Jack of Diamonds";
  73. deck[23] = "Queen of Diamonds";
  74. deck[24] = "King of Diamonds";
  75. deck[25] = "Ace of Diamonds";
  76. for (i=26; i < 35; i++) deck[i] = (i-24) +" of Hearts";
  77. deck[35] = "Jack of Hearts";
  78. deck[36] = "Queen of Hearts";
  79. deck[37] = "King of Hearts";
  80. deck[38] = "Ace of Hearts";
  81. for (i=39; i < 48; i++) deck[i] = (i-37) +" of Spades";
  82. deck[48] = "Jack of Spades";
  83. deck[49] = "Queen of Spades";
  84. deck[50] = "King of Spades";
  85. deck[51] = "Ace of Spades";
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement