Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- bool is_face(string s) {
- return isalpha(s[1]) && s[1] != 'T';
- }
- void print(deque<string> p) {
- while (sz(p)) cout << p.back() << " ", p.pop_back();
- cout << endl;
- }
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- string s;
- while (1) {
- cin >> s;
- if (s == "#") break;
- deque<string> heap;
- vector<deque<string>> p(2);
- p[0].push_back(s);
- for (int i = 1; i < 52; i++) {
- cin >> s;
- p[i % 2].push_back(s);
- }
- int turn = 1;
- bool game_over = false;
- //cout << "0: ";
- //print(p[0]);
- heap.push_back(p[0].back()), p[0].pop_back();
- int winner = 0;
- map<char, int> mp = { {'A', 4}, {'K', 3}, {'Q', 2}, {'J', 1} };
- while (!game_over) {
- //cout << turn << ": ";
- //print(p[turn]);
- if (is_face(heap.back())) {
- int plays = mp[heap.back()[1]];
- while (plays-- && !p[turn].empty() && !is_face(p[turn].back())) {
- heap.push_back(p[turn].back());
- p[turn].pop_back();
- }
- if (plays == -1) {
- while (sz(heap)) p[!turn].push_front(heap.front()), heap.pop_front();
- }
- else if (p[turn].empty()) {
- game_over = true;
- winner = !turn;
- }
- else heap.push_back(p[turn].back()), p[turn].pop_back();
- }
- else {
- if (p[turn].empty()) game_over = true, winner = !turn;
- else heap.push_back(p[turn].back()), p[turn].pop_back();
- }
- turn = !turn;
- }
- cout << !winner + 1 << " " << setw(2) << sz(p[winner]) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement