-
Notifications
You must be signed in to change notification settings - Fork 11
/
vjudge_UVA-10388_snap.cpp
101 lines (85 loc) · 2.86 KB
/
vjudge_UVA-10388_snap.cpp
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
// UVa 10388 Snap
// Use basic deque operations and the random() function to simulate a card game
// Annoying presentation errors from printing extra newline chars. Also remember to clean up data structures between test cases!
// Time: O(1) since limited by 1000 moves, Memory: O(N) where N is the number of cards in the game
#include <bits/stdc++.h>
using namespace std;
deque<char> jane_down, jane_up, john_down, john_up;
int T;
int main(){
cin >> T;
for(int tc = 0; tc< T; tc++){
// Parse Input
string temp;
cin >> temp;
for (auto c: temp){
jane_down.push_back(c);
}
cin >> temp;
for (auto c: temp){
john_down.push_back(c);
}
// Perform Simuation
bool finished = false;
for (int move=1; move<= 1000; move++){
jane_up.push_front(jane_down.front());
jane_down.pop_front();
john_up.push_front(john_down.front());
john_down.pop_front();
if (john_up.front() == jane_up.front()){
bool jane_winner = !(random()/141%2);
if (jane_winner){
while(!john_up.empty()){
jane_up.push_front(john_up.back());
john_up.pop_back();
}
cout << "Snap! for Jane: ";
for (auto i:jane_up) cout << i;
cout << endl;
}
else{
while(!jane_up.empty()){
john_up.push_front(jane_up.back());
jane_up.pop_back();
}
cout << "Snap! for John: ";
for (auto i:john_up) cout << i;
cout << endl;
}
}
if (jane_down.empty() && jane_up.empty()){
cout << "John wins." << endl;
finished = true;
break;
}
if (john_down.empty() && john_up.empty()){
cout << "Jane wins." << endl;
finished = true;
break;
}
if(jane_down.empty()){
while(!jane_up.empty()){
jane_down.push_front(jane_up.front());
jane_up.pop_front();
}
}
if(john_down.empty()){
while(!john_up.empty()){
john_down.push_front(john_up.front());
john_up.pop_front();
}
}
}
if (!finished){
cout << "Keeps going and going ..." << endl;
}
if (tc != T-1)
cout << endl;
// Clean up
jane_down.clear();
jane_up.clear();
john_down.clear();
john_up.clear();
}
return 0;
}