-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP170.cpp
62 lines (59 loc) · 1.48 KB
/
P170.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
#include <iostream>
#include <stdio.h>
#include <stack>
int ctoi(char c) {
switch(c) {
case 'A':
return 0;
case 'K':
return 12;
case 'Q':
return 11;
case 'J':
return 10;
case 'T':
return 9;
default:
return c-'0'-1;
}
}
int main() {
while(true) {
std::stack<std::pair<int, std::string> > stacks[13];
// read cards:
std::string card;
std::stack<std::string> inStack;
for(int i = 0; i < 4*13; ++i) {
std::cin >> card;
if(card[0] == '#')
return 0;
inStack.push(card);
}
int stackI = 0;
while(!inStack.empty()) {
card = inStack.top();
inStack.pop();
int val = ctoi(card[0]);
//std::cerr << "Reading " << card << " -> " << val << std::endl;
stacks[stackI].push(std::make_pair(val, card));
++stackI;
if(stackI == 13)
stackI = 0;
}
// play:
int currentVal = stacks[12].top().first;
std::string lastExposed = stacks[12].top().second;
//std::cerr << "Start Exposing " << lastExposed << " from stack 12 -> " << currentVal << std::endl;
stacks[12].pop();
int exposed = 1;
while(!stacks[currentVal].empty()) {
int v = stacks[currentVal].top().first;
lastExposed = stacks[currentVal].top().second;
stacks[currentVal].pop();
//std::cerr << "Exposing " << lastExposed << " from stack " << currentVal << " -> " << v << std::endl;
currentVal = v;
++exposed;
}
printf("%02i,%s\n", exposed, lastExposed.c_str());
}
}