Source code for submission s1388

Rhino.java

  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collections;
  6.  
  7. public class Rhino {
  8. public static int [] ratia;
  9. public static void main(String[] args) throws Exception {
  10. String str;
  11. String[] radek;
  12. int n;
  13.  
  14. Karta [] hodnoceny = new Karta [5];
  15. Karta [] spolecny = new Karta [5];
  16. Karta [][] ruce;
  17.  
  18.  
  19. while((str = br.readLine()) != null){
  20. n = Integer.parseInt(str);
  21. str = br.readLine();
  22. str = str.replace("X", ":");
  23. str = str.replace("J", ";");
  24. str = str.replace("Q", "<");
  25. str = str.replace("K", "=");
  26. str = str.replace("A", ">");
  27.  
  28. str = str.replace("c", "a");
  29. str = str.replace("d", "b");
  30. str = str.replace("h", "c");
  31. str = str.replace("s", "d");
  32. radek = str.split(" ");
  33. for (int i = 0; i < 5; i++)
  34. {
  35. char cislo = radek[i].charAt(0);
  36. char druh = radek[i].charAt(1);
  37. spolecny[i] = new Karta(cislo, druh);
  38. }
  39.  
  40. ruce = new Karta [n][2];
  41. ratia = new int [n];
  42.  
  43. for (int i = 0; i < n; i++)
  44. {
  45. str = br.readLine();
  46. str = str.replace("X", ":");
  47. str = str.replace("J", ";");
  48. str = str.replace("Q", "<");
  49. str = str.replace("K", "=");
  50. str = str.replace("A", ">");
  51.  
  52. str = str.replace("c", "a");
  53. str = str.replace("d", "b");
  54. str = str.replace("h", "c");
  55. str = str.replace("s", "d");
  56. radek = str.split(" ");
  57.  
  58. ruce[i][0] = new Karta(radek[0].charAt(0), radek[0].charAt(1));
  59. ruce[i][1] = new Karta(radek[1].charAt(0), radek[1].charAt(1));
  60.  
  61. for (int j = 0; j < 3; j++)
  62. {
  63. for (int k = 1; k < 3; k++)
  64. {
  65. for (int l = 2; l < 4; l++)
  66. {
  67. if (j != k && j != l && k != l)
  68. {
  69. hodnoceny[0] = ruce[i][0];
  70. hodnoceny[1] = (ruce[i][0]);
  71. hodnoceny[2] = (spolecny[j]);
  72. hodnoceny[3] = (spolecny[k]);
  73. hodnoceny[4] = (spolecny[l]);
  74. vyhodnotit(i, hodnoceny);
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82.  
  83. private static void vyhodnotit(int index, Karta [] hodnoceny)
  84. {
  85. Arrays.sort(hodnoceny);
  86.  
  87. boolean isStraight = false;
  88. boolean isFlush = true;
  89.  
  90. //royal flush
  91. if (hodnoceny[0].cislo == 0 && hodnoceny[1].cislo == 10 &&hodnoceny[2].cislo == 11 &&hodnoceny[3].cislo == 12 &&hodnoceny[4].cislo == 13 )
  92. {
  93. isStraight = true;
  94. }
  95. if (!isStraight)
  96. {
  97. isStraight = true;
  98. for (int i = 1; i < 5; i++)
  99. {
  100. if (hodnoceny[i].cislo != hodnoceny[i+1].cislo)
  101. {
  102. isStraight = false;
  103. break;
  104. }
  105. }
  106. }
  107. for (int i = 0; i < 4; i++)
  108. if (hodnoceny[i].barva != hodnoceny[i+1].barva)
  109. isFlush = false;
  110. if (isStraight && isFlush)
  111. ratia[index] = 8;
  112. else if (isFlush)
  113. ratia[index] = 5;
  114. else if (isStraight)
  115. ratia[index] = 4;
  116.  
  117.  
  118. boolean isPoker = false;
  119. //Poker
  120. if (hodnoceny[1].cislo == hodnoceny[2].cislo && hodnoceny[1].cislo == hodnoceny[2].cislo)
  121.  
  122.  
  123. if (hodnoceny[i].cislo != hodnoceny[i+1].cislo)
  124. {
  125. isStraight = false;
  126. break;
  127. }
  128. }
  129. if (!isStraight)
  130. {
  131. isStraight = true;
  132. for (int i = 1; i < 5; i++)
  133. {
  134. if (hodnoceny[i].cislo != hodnoceny[i+1].cislo)
  135. {
  136. isStraight = false;
  137. break;
  138. }
  139. }
  140. }
  141.  
  142. }
  143. }
  144.  
  145. class Karta implements Comparable<Karta>
  146. {
  147. char cislo;
  148. char barva;
  149.  
  150. public Karta(char cislo, char barva)
  151. {
  152. this.cislo = (char)(((int)(cislo)-(int)('0'))%14);
  153. this.barva = barva;
  154. }
  155.  
  156. public int compareTo(Karta o)
  157. {
  158. return this.cislo - o.cislo;
  159. }
  160. }