UVa 451 - Poker Solitaire Evaluator

contents

  1. 1. Input
  2. 2. Output
  3. 3. Sample Input
  4. 4. Sample Output
  5. 5. Solution

Input

The input will contain several test cases. First line of the input is the an integer which indicate the number of test case followed by a blank line. Each consecutive test case will also separated by a blank line.

Each test case gets 25 cards, 5 cards per line. Each card consists of two characters. The first represents the rank of the card: A',2’, 3',4’, 5',6’, 7',8’, 9',X’, J',Q’, K'. The second represents the suit of the card:S’, H',D’, `C’.

The cards are dealt into a tex2html_wrap_inline44 square. Each row and column is evaluated to determine the highest hand type for which its 5 cards qualify. The hand types, from low to high, are Nothing, Pair, Two Pair, Three of a Kind, Straight, Flush, Full House, Four of a Kind, Straight Flush. A hand qualifies only once, and then only for its highest type. For example, a Four of a Kind does not count as two pair or three of a kind.

Output

For each test case output a list of 9 integers, telling how many hands of each handtype were found. from lowest to highest, being:

Nothing: does not qualify as any of the following. Example: AC, 3H, QS, JD, 7D.

One Pair: contains two cards of the same rank and does not qualify for any of the following. Example: 2C, 3H, 4H, 2H, KD.

Two Pair: contains two cards of one rank and two cards of another and does not qualify for any of the following. Example: 2C, 3H, 4H, 2H, 4D.

Three of a Kind: contains three cards of the same rank and does not qualify for any of the following. Example: QS, KH, 2C, QD, QC.

Straight: the five cards of the hand may be sorted on rank so that an unbroken sequence of 5 ranks is formed and the hand does not qualify for any of the following. There can be cycle through Ace. That is AC, 2H, 4D, 3H, 5S forms a straight, as does JH, XD,QC, KD, AS and QC, KD, AS, 2H, 3D.

Flush: the five cards are all of the same suit and the hand does not qualify for any of the following. Example: 5D, AD, KD, 7D, QD.

Full House: the hand contains three cards of one rank and two cards of another. Example: 3C, QS, QD, 3H, 3S.

Four of a kind: the hand contains four cards of the same rank. Example: AS, AD, AH, 7C, AC.

Straight Flush: the hand meets the criteria for being both a straight and a flush. 

Two consecutive output will separated by a blank line.

For the example below, the five rows evaluate to Straight Flush, Straight, Pair, Flush, Three of a Kind. The Five columns evaluate to Four of A Kind, Full House, Two Pair, Nothing, and Two Pair.

Sample Input

1
2
3
4
5
6
7
1
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
XH 3C XC XS 8C

Sample Output

1
1, 1, 2, 1, 1, 1, 1, 1, 1

Solution

一張撲克牌有花色(Clubs, Diamonds, Hearts, Spades,分別以C,D,H,S來代表)及點數(2,3,4,5,6,7,8,9,10, jack, queen, king, ace,分別以2,3,4,5,6,7,8,9,X,J,Q,K,A來代表)。有一種常見的撲克牌遊戲叫”梭哈”(就是你在電影賭神中常見的那種遊戲),每個人手上有5張牌,並且依照以下的規則給予每手牌1-9的整數值。注意:每手牌只能有一個值(高的那一個),例如:Four of a kind就不能算為two pairs 或 three of a kind.

  1. Nothing:(中文翻譯:不知道,就是最爛的就是了)沒有以下任何情況就屬於nothing。例如:AH 9D 7C 3H 2D
  2. One pair:(中文翻譯:1對)有2張牌同一個點數,另3張牌皆不同點數。例如:8H 8D KC 5H 2D
  3. Two pairs:(中文翻譯:2對)有2組2張牌同一個點數,另1張牌不同點數。例如:8H 8D 5C 5H 9D
  4. Three of a kind:(中文翻譯:3條)3張牌同一個點數,另2張牌不同點數。例如:8H 8D 8C AH 9D
  5. Straight:(中文翻譯:順子)5張牌的點數為連續的並且可以A連接2成一圈。(所以:點數T J Q K A是順子,A 2 3 4 5是順子,Q K A 2 3也是順子)例如:8H 9H TH JH QD
  6. Flush:(中文翻譯:同花)5張牌同一花色。例如:6H 9H TH JH QH
  7. Full House:(中文翻譯:葫蘆)3張同一點數,另2張同一點數。例如:8H 8D 8C 7S 7D
  8. Four of a kind:(中文翻譯:4條或鐵枝)4張牌同一個點數。例如:8H 8D 8C 8S 9D
  9. Straight flush: (中文翻譯:同花順)5張牌同一花色,並且形成一個順子。例如:8H 9H TH JH QH

給你25張牌排成5*5的樣子。你的任務就是算出5列(橫的)及5欄(直的)這10手牌所形成的統計結果。

luckycat 翻譯

依序判斷,只能硬暴。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int getSuit(char c) {
switch(c) {
case 'C': return 0;
case 'D': return 1;
case 'H': return 2;
case 'S': return 3;
}
}
int getRank(char c) {
switch(c) {
case '0' ... '9': return c - '0';
case 'A': return 1;
case 'X': return 10;
case 'J': return 11;
case 'Q': return 12;
case 'K': return 13;
}
}
bool suitCmp(pair<int, int> x, pair<int, int> y) {
if(x.first != y.first)
return x.first < y.first;
return x.second < y.second;
}
bool rankCmp(pair<int, int> x, pair<int, int> y) {
if(x.second != y.second)
return x.second < y.second;
return x.first < y.first;
}
int getType(vector< pair<int, int> > cards) {
vector< pair<int, int> >::iterator it;
sort(cards.begin(), cards.end(), suitCmp);
if(cards[0].first == cards[4].first) { // all same suit
for(int i = 0; i < 13; i++) {
int ok = 1;
for(int j = 0; j < 5; j++) {
int r = (i + j)%13 + 1;
it = find(cards.begin(), cards.end(), make_pair(cards[0].first, r));
ok &= it != cards.end();
}
if(ok)
return 9;
}
}
sort(cards.begin(), cards.end(), rankCmp);
if(cards[0].second == cards[3].second ||
cards[1].second == cards[4].second)
return 8;
sort(cards.begin(), cards.end(), rankCmp);
if(cards[0].second == cards[2].second &&
cards[3].second == cards[4].second)
return 7;
if(cards[0].second == cards[1].second &&
cards[2].second == cards[4].second)
return 7;
sort(cards.begin(), cards.end(), suitCmp);
if(cards[0].first == cards[4].first)
return 6;
sort(cards.begin(), cards.end(), suitCmp);
for(int i = 0; i < 13; i++) {
int ok = 1;
for(int j = 0; j < 5; j++) {
int r = (i + j)%13 + 1;
for(int k = 0; k < 4; k++) {
it = find(cards.begin(), cards.end(), make_pair(k, r));
if(it != cards.end())
break;
}
ok &= it != cards.end();
}
if(ok)
return 5;
}
sort(cards.begin(), cards.end(), rankCmp);
if(cards[0].second == cards[2].second ||
cards[1].second == cards[3].second ||
cards[2].second == cards[4].second)
return 4;
sort(cards.begin(), cards.end(), rankCmp);
if(cards[0].second == cards[1].second &&
cards[2].second == cards[3].second)
return 3;
if(cards[0].second == cards[1].second &&
cards[3].second == cards[4].second)
return 3;
if(cards[1].second == cards[2].second &&
cards[3].second == cards[4].second)
return 3;
sort(cards.begin(), cards.end(), rankCmp);
for(int i = 1; i < 5; i++)
if(cards[i].second == cards[i-1].second)
return 2;
return 1;
}
int main() {
int testcase;
char grid[5][5][5];
scanf("%d", &testcase);
while(testcase--) {
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++)
scanf("%s", grid[i][j]);
int cnt[10] = {};
for(int i = 0; i < 5; i++) {
vector< pair<int, int> > cc;
for(int j = 0; j < 5; j++)
cc.push_back(make_pair(getSuit(grid[i][j][1]), getRank(grid[i][j][0])));
int f = getType(cc);
cnt[f]++;
}
for(int i = 0; i < 5; i++) {
vector< pair<int, int> > cc;
for(int j = 0; j < 5; j++)
cc.push_back(make_pair(getSuit(grid[j][i][1]), getRank(grid[j][i][0])));
int f = getType(cc);
cnt[f]++;
}
for(int i = 1; i <= 9; i++) {
if(i > 1) printf(", ");
printf("%d", cnt[i]);
}
puts("");
if(testcase)
puts("");
}
return 0;
}
/*
2
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
XH 3C XC XS 8C
AS 2S 3S 4S 6S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
XH 3C XC XS 8C
*/