-
Notifications
You must be signed in to change notification settings - Fork 0
/
SW9760_PokerGame.java
78 lines (69 loc) Β· 2.25 KB
/
SW9760_PokerGame.java
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
package ssafy.workshop;
import java.io.*;
import java.util.HashMap;
public class SW9760_PokerGame {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(in.readLine());
for (int tc = 1; tc <= T; tc++) {
String[] str = in.readLine().split(" ");
// μΉ΄λ νΈλ μ
λ ₯ λ° νλ³
boolean isStraight = false, isFlush = false;
boolean isFour = false, isThree = false; int pair = 0;
HashMap<Character, Integer> suite = new HashMap<Character, Integer>();
int[] rank = new int[14];
for (int i = 0; i < 5; i++) {
char p = str[i].charAt(0); // λͺ¨μ
int cnt = suite.get(p) == null ? 0 : suite.get(p);
suite.put(p, cnt+1);
if (cnt+1 == 5) isFlush = true;
char n = str[i].charAt(1); // μ«μ
int num = 0;
if (n == 'A') num = 1;
else if (n == 'T') num = 10;
else if (n == 'J') num = 11;
else if (n == 'Q') num = 12;
else if (n == 'K') num = 13;
else num = n-'0';
rank[num]++;
cnt = rank[num];
if (cnt == 4) isFour = true;
if (cnt == 3) isThree = true;
if (cnt == 2) pair++;
}
// μ€νΈλ μ΄νΈ νλ³
if (pair == 0 && !isThree && !isFour) {
boolean flag = false;
int cnt = 0;
for (int i = 1; i <= 13; i++) {
if (cnt == 5) break;
if (rank[i] != 0) {
if (!flag) flag = true;
cnt++;
if (i == 13 && rank[1] == 1) cnt++;
} else {
if (!flag) continue;
if (i == 2) {
i = 9; continue;
}
flag = false; break;
}
}
if (flag && cnt == 5) isStraight = true;
}
// μΉ΄λ νΈλμ μ’
λ₯ νλ³
String answer = "High card";
if (isStraight && isFlush) answer = "Straight Flush";
else if (isFour) answer = "Four of a Kind";
else if (isThree && pair == 2) answer = "Full House";
else if (isFlush) answer = "Flush";
else if (isStraight) answer = "Straight";
else if (isThree) answer = "Three of a kind";
else if (pair == 2) answer = "Two pair";
else if (pair == 1) answer = "One pair";
sb.append("#").append(tc).append(" ").append(answer).append("\n");
}
System.out.println(sb.toString());
}
}