fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #define LEN 32
  6. #define MAXINPUT 200
  7.  
  8. enum types {
  9. FIVEKIND,
  10. FOURKIND,
  11. FULLHOUSE,
  12. THREEKIND,
  13. TWOPAIR,
  14. ONEPAIR,
  15. HIGHCARD
  16. };
  17.  
  18. struct {
  19. char hand[6];
  20. int bid;
  21. enum types type;
  22. } input[MAXINPUT];
  23.  
  24. int inputindex;
  25.  
  26.  
  27.  
  28. enum types check_hand(char cards[])
  29. {
  30. int alphabet[26];
  31. int numbers[10];
  32. memset(alphabet, 0, sizeof(alphabet));
  33. memset(numbers, 0, sizeof(numbers));
  34.  
  35. for(int i=0;i<strlen(cards);i++)
  36. {
  37. if(cards[i]>='0'&&cards[i]<='9')
  38. numbers[cards[i]-'0']++;
  39. else
  40. alphabet[cards[i]-'A']++;
  41. }
  42.  
  43. int count[5];
  44. int k=0;
  45. memset(count,0,sizeof(count));
  46. for(int i=0;i<26;i++)
  47. if(alphabet[i])
  48. count[k++]++;
  49.  
  50. for(int i=0;i<10;i++)
  51. if(numbers[i])
  52. count[k++]++;
  53.  
  54. int max=0;
  55. for(int i=0;i<5;i++)
  56. if(max<count[i])
  57. max=count[i];
  58.  
  59. int pairs=0;
  60.  
  61. switch(max)
  62. {
  63. case 5:
  64. return FIVEKIND;
  65. break;
  66.  
  67. case 4:
  68. return FOURKIND;
  69. break;
  70.  
  71. case 3:
  72. for(int i=0;i<5;i++)
  73. if(count[i]==2)
  74. return FULLHOUSE;
  75. return THREEKIND;
  76. break;
  77.  
  78. case 2:
  79. pairs=0;
  80. for(int i=0;i<5;i++)
  81. if(count[i]==2)
  82. pairs++;
  83. if(pairs==2)
  84. return TWOPAIR;
  85. return ONEPAIR;
  86. break;
  87.  
  88. default:
  89. return HIGHCARD;
  90. break;
  91. }
  92.  
  93. return HIGHCARD;
  94. }
  95.  
  96.  
  97. int main()
  98. {
  99. char line[LEN];
  100. while(fgets(line,LEN,stdin)!=NULL)
  101. {
  102. char *token;
  103. token=strtok(line," ");
  104. strcpy(input[inputindex].hand, token);
  105.  
  106. token=strtok(NULL," ");
  107. input[inputindex].bid = atoi(token);
  108.  
  109. inputindex++;
  110. }
  111.  
  112. for(int i=0;i<inputindex;i++)
  113. input[i].type = check_hand(input[i].hand);
  114.  
  115.  
  116. for(int i=0;i<inputindex;i++)
  117. printf("%d\n",input[i].type);
  118.  
  119. return 0;
  120. }
Success #stdin #stdout 0s 5284KB
stdin
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
stdout
6
6
6
6
6