Source code for submission s1355

main.c

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int hraci;
  5.  
  6. int barva_stul[5];
  7. int hodnota_stul[5];
  8.  
  9. int barva[2 * 10];
  10. int hodnota[2 * 10];
  11.  
  12. int hodnoceni_high[10];
  13. int hodnoceni_low[10];
  14.  
  15. int maxhigh, maxlow;
  16.  
  17. int rozhodni(int* tabulka, int p)
  18. {
  19. int i, j;
  20. int counter;
  21. int postupka = 0;
  22.  
  23. int dvojice = 0, trojice = 0, ctverice = 0;
  24. int vicparu = 0;
  25.  
  26. int karta = 0;
  27.  
  28. int full_tri = 0, full_dva = 0;
  29. int flush = 0;
  30.  
  31. int fullhouse = 0;
  32.  
  33. int royal_flush = 0;
  34.  
  35. counter = 0;
  36. for (i = 1; i <= 14; i++)
  37. {
  38. if (tabulka[4 * 16 + i])
  39. counter++;
  40. else
  41. counter = 0;
  42. if (counter >= 5)
  43. postupka = i;
  44. }
  45.  
  46. for (i = 1; i <= 14; i++)
  47. {
  48. if (tabulka[4 * 16 + i] >= 2)
  49. {
  50. if (dvojice)
  51. vicparu++;
  52. dvojice += i;
  53. }
  54. if (tabulka[4 * 16 + i] >= 3)
  55. trojice += i;
  56. if (tabulka[4 * 16 + i] >= 4)
  57. ctverice += i;
  58.  
  59. karta += i;
  60. }
  61.  
  62. hodnoceni_low[p] = karta + 16 * dvojice + 16 * 16 * vicparu + 16 * 16 * 16 * trojice
  63. + 16 * 16* 16*16 * postupka;
  64.  
  65. for (j = 0; j < 4; j++)
  66. {
  67. if (tabulka[j * 16 + 15] >= 5)
  68. flush++;
  69. }
  70.  
  71.  
  72. for (i = 1; i <= 14; i++)
  73. {
  74. if (tabulka[4 * 16 + i] == 3)
  75. full_tri = i;
  76. if (tabulka[4 * 16 + i] == 2)
  77. full_dva = i;
  78. }
  79. fullhouse = full_dva ? full_tri : 0;
  80.  
  81. if (postupka)
  82. {
  83. for (j = 0; j < 4; j++)
  84. {
  85. royal_flush = postupka;
  86. for (i = postupka; i >= postupka - 5; i--)
  87. {
  88. if (tabulka[j * 16 + i] == 0)
  89. royal_flush = 0;
  90. }
  91. if (royal_flush)
  92. break;
  93. }
  94. }
  95.  
  96. hodnoceni_high[i] = flush + 16 * fullhouse + 16 * 16 * ctverice + 16*16*16 * royal_flush;
  97.  
  98. return 0;
  99. }
  100.  
  101.  
  102. int ohodnot(int p)
  103. {
  104. int i;
  105. int j;
  106.  
  107. int tabulka[5 * 16];
  108. memset(tabulka, 0, 5 * 16 * sizeof(int));
  109.  
  110. for (i = 0; i < 5; i++)
  111. {
  112. tabulka[16 * barva_stul[i] + hodnota_stul[i]]++;
  113. if (hodnota_stul[i] == 14)
  114. {
  115. tabulka[16 * barva_stul[i] + 1]++;
  116. }
  117. }
  118.  
  119. for (i = p * 2; i <= p * 2 + 1; i++)
  120. {
  121. tabulka[16 * barva[i] + hodnota[i]]++;
  122. if (hodnota[i] == 14)
  123. {
  124. tabulka[16 * barva[i] + 1]++;
  125. }
  126. }
  127.  
  128.  
  129. for (i = 2; i <= 14; i++)
  130. for (j = 0; j < 4; j++)
  131. tabulka[16 * 4 + i] += tabulka[16 * j + i];
  132.  
  133. for (j = 0; j < 4; j++)
  134. for (i = 2; i <= 14; i++)
  135. tabulka[16 * j + 15] += tabulka[16 * j + i];
  136.  
  137. rozhodni(tabulka, p);
  138. /* */
  139. /*
  140.   printf("\n");
  141.   printf("\n");
  142.   for (j = 0; j < 5; j++)
  143.   {
  144.   for (i = 0; i < 16; i++)
  145.   printf("%d", tabulka[16 * j + i]);
  146.  
  147.   printf("\n");
  148.   }
  149.   */
  150. }
  151.  
  152. int nactikartu(int* bar, int* hod)
  153. {
  154. char s[4];
  155. scanf("%s", s);
  156. printf("%s ** ", s);
  157. if (s[0] >= '0' && s[0] <= '9')
  158. *hod = s[0] - '0';
  159. else switch (s[0])
  160. {
  161. case 'X': *hod = 10;break;
  162. case 'J': *hod = 11;break;
  163. case 'Q': *hod = 12;break;
  164. case 'K': *hod = 13;break;
  165. case 'A': *hod = 14;break;
  166. default:;
  167. }
  168.  
  169. switch (s[1])
  170. {
  171. case 'c': *bar = 0;break;
  172. case 'd': *bar = 1;break;
  173. case 'h': *bar = 2;break;
  174. case 's': *bar = 3;break;
  175. default:;
  176. }
  177.  
  178. /* printf("%d %d =", *bar, *hod);*/
  179.  
  180. return 0;
  181. }
  182.  
  183. int main(int argc, char *argv[])
  184. {
  185. int i;
  186. int mezera = 0;
  187.  
  188. while (scanf("%d", &hraci) == 1)
  189. {
  190. for (i = 0; i < 5; i++)
  191. nactikartu(barva_stul + i, hodnota_stul + i);
  192. for (i = 0; i < hraci * 2; i++)
  193. {
  194. nactikartu(barva + i, hodnota + i);
  195. }
  196.  
  197. for (i = 0; i < hraci; i++)
  198. {
  199. ohodnot(i);
  200. }
  201.  
  202. maxhigh = 0;
  203. maxlow = 0;
  204. for (i = 0; i < hraci; i++)
  205. {
  206. if (hodnoceni_high[i] > maxhigh)
  207. {
  208. if (hodnoceni_low[i] > maxlow)
  209. {
  210. maxlow = hodnoceni_low[i];
  211. maxhigh = hodnoceni_high[i];
  212. }
  213. }
  214. }
  215.  
  216. for (i = 0; i < hraci; i++)
  217. {
  218. if (hodnoceni_high[i] == maxhigh)
  219. {
  220. if (hodnoceni_low[i] == maxlow)
  221. {
  222. if (mezera)
  223. printf(" ");
  224. printf("%d", i);
  225. mezera = 1;
  226. }
  227. }
  228. }
  229. printf("\n");
  230.  
  231. }
  232.  
  233. return 0;
  234. }
  235.