-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20923.cpp
More file actions
83 lines (75 loc) · 2.03 KB
/
20923.cpp
File metadata and controls
83 lines (75 loc) · 2.03 KB
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
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
typedef vector<deque<int>> cards;
const int DO = 0, SU = 1;
// 승리 판단하기
string judge(cards& deck)
{
int do_deck = deck[DO].size(), su_deck = deck[SU].size();
if (do_deck > su_deck) {
return "do";
}
else if (do_deck < su_deck) {
return "su";
}
return "dosu";
}
// 그라운드에서 덱으로 카드 옮기기
void groundToDeck(deque<int>& deck, deque<int>& ground) {
while (!ground.empty()) {
deck.push_back(ground.back());
ground.pop_back();
}
}
// 종을 울릴 수 있는 사람 판단
int whoCanRingTheBell(cards& deck, cards& ground) {
if (!ground[DO].empty() && ground[DO].front() == 5) {
return DO;
}
else if (!ground[SU].empty() && ground[SU].front() == 5) {
return DO;
}
else if (!ground[DO].empty() && !ground[SU].empty() && (ground[DO].front() + ground[SU].front() == 5)) {
return SU;
}
return -1;
}
void ringTheBell(int player, cards& deck, cards& ground) {
groundToDeck(deck[player], ground[!player]); // 카드 가져가기 (상대 그라운드 -> 본인 덱)
groundToDeck(deck[player], ground[player]); // 카드 가져가기 (본인 그라운드 -> 본인 덱)
}
// 게임 진행
string game(int m, cards& deck, cards& ground) {
bool turn = DO; // 도도 먼저
while (m--)
{
ground[turn].push_front(deck[turn].front()); // 카드 내려놓기(덱 -> 그라운드)
deck[turn].pop_front();
if (deck[turn].empty()) {
break;
}
int bell = whoCanRingTheBell(deck, ground); // 벨을 울릴 수 있는 사람
if (bell != -1) { // 종을 친 경우
ringTheBell(bell, deck, ground);
}
turn = !turn; // 차례 바꾸기
}
return judge(deck);
}
int main()
{
int n, m, card1, card2;
cards deck(2), ground(2); // 0: 도도, 1: 수연
// 입력
cin >> n >> m;
while (n--) {
cin >> card1 >> card2;
deck[0].push_front(card1);
deck[1].push_front(card2);
}
// 출력 & 연산
cout << game(m, deck, ground) << '\n';
return 0;
}