Skip to content

Commit b874f2e

Browse files
committed
boj 2621 카드게임
1 parent 9bcfd96 commit b874f2e

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

Case Work/2621.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#define MAX 5
4+
using namespace std;
5+
6+
char list[MAX][2];
7+
8+
bool isSameColor() {
9+
return list[0][0] == list[1][0] && list[1][0] == list[2][0] && list[2][0] == list[3][0] && list[3][0] == list[4][0];
10+
}
11+
12+
int chkStraight(char *c) {
13+
for (int i = 1; i < MAX; i++) {
14+
if (c[i] - c[i - 1] != 1) return 0;
15+
}
16+
return c[MAX - 1] - '0';
17+
}
18+
19+
int chkSameFourCards(char* c) {
20+
if (c[0] == c[3]) return c[0] - '0';
21+
else if (c[1] == c[4]) return c[1] - '0';
22+
return 0;
23+
}
24+
25+
int chkThreeTwo(char* c) {
26+
if (c[0] != c[1] || c[3] != c[4]) return 0;
27+
if (c[1] == c[2]) return (c[0] - '0') * 10 + c[4] - '0' + 700;
28+
else if (c[2] == c[3]) return (c[4] - '0') * 10 + c[0] - '0' + 700;
29+
return 0;
30+
}
31+
32+
int chkThree(char* c) {
33+
for (int i = 2; i < MAX; i++) {
34+
if (c[i - 2] == c[i - 1] && c[i - 1] == c[i]) return c[i] - '0';
35+
}
36+
return 0;
37+
}
38+
39+
int chkTwoTwo(char* c) {
40+
int mx = 0;
41+
int mn = 0;
42+
for (int i = 1; i < MAX; i++) {
43+
if (c[i - 1] != c[i]) continue;
44+
if (!mx) mx = c[i] - '0';
45+
else mn = c[i] - '0';
46+
}
47+
if (mn > mx) swap(mn, mx);
48+
49+
if (!mn) return 0;
50+
return mx * 10 + mn + 300;
51+
}
52+
53+
int chkTwo(char* c) {
54+
for (int i = 1; i < MAX; i++) {
55+
if (c[i - 1] != c[i]) continue;
56+
return c[i] - '0' + 200;
57+
}
58+
return 0;
59+
}
60+
61+
void func() {
62+
char* tmp = new char[] { list[0][1], list[1][1], list[2][1], list[3][1], list[4][1] };
63+
sort(tmp, tmp + MAX);
64+
65+
int st = chkStraight(tmp);
66+
int fc = chkSameFourCards(tmp);
67+
int tht = chkThreeTwo(tmp);
68+
int th = chkThree(tmp);
69+
int ttwo = chkTwoTwo(tmp);
70+
int two = chkTwo(tmp);
71+
if (isSameColor() && st) cout << st + 900 << '\n';
72+
else if (fc) cout << fc + 800 << '\n';
73+
else if (tht) cout << tht << '\n';
74+
else if (isSameColor()) cout << tmp[4] - '0' + 600 << '\n';
75+
else if (st) cout << st + 500 << '\n';
76+
else if (th) cout << th + 400 << '\n';
77+
else if (ttwo) cout << ttwo << '\n';
78+
else if (two) cout << two << '\n';
79+
else cout << tmp[4] - '0' + 100 << '\n';
80+
}
81+
82+
void input() {
83+
for (int i = 0; i < MAX; i++) {
84+
cin >> list[i][0] >> list[i][1];
85+
}
86+
}
87+
88+
int main() {
89+
cin.tie(NULL); cout.tie(NULL);
90+
ios::sync_with_stdio(false);
91+
92+
input();
93+
func();
94+
95+
return 0;
96+
}

0 commit comments

Comments
 (0)