Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <stdio.h>
- #include <stack>
- #include <list>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- #include <sstream>
- #include <bitset>
- using namespace std;
- struct card{
- int val;
- char nipe;
- };
- typedef struct card Card;
- bool way(Card a, Card b) {
- if(a.val == b.val){
- if(a.nipe == 'C'){
- return 0;
- }else if(a.nipe == 'D'){
- if(b.nipe == 'C') return 1;
- return 0;
- }else if(a.nipe == 'H'){
- if(b.nipe == 'S') return 0;
- return 1;
- }return 1;
- }
- return a.val > b.val;}
- int main(){
- int p, m, n;
- cin >> p >> m >> n;
- while((p+m+n)){
- vector<Card> play[12];
- vector<Card> buy;
- Card desc;
- for(int i=0; i<p; ++i){
- for(int j=0; j<m; ++j){
- Card c;
- cin >> c.val >> c.nipe;
- play[i].push_back(c);
- }
- }
- cin >> desc.val >> desc.nipe;
- for(int i=p*m+1; i<n; ++i){
- Card c;
- cin >> c.val >> c.nipe;
- buy.push_back(c);
- }
- int x = p-1;
- while(x--){
- sort(play[x].begin(), play[x].end(), way);
- }
- int it = 0;
- int direc = 1;
- x = p-1;
- int zerou = 0;
- while(true){
- switch(desc.val){
- case 12: direc *= -1;
- if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
- desc = play[it].front();
- play[it].erase(play[it].begin());
- if(!play[it].size()){
- zerou = 1;
- }
- }else{
- play[it].push_back(buy.front());
- buy.erase(buy.begin());
- sort(play[it].begin(), play[it].end(), way);
- if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
- desc = play[it].front();
- play[it].erase(play[it].begin());
- }
- }
- break;
- case 7: play[it+direc].push_back(buy.front());
- buy.erase(buy.begin());
- play[it+direc].push_back(buy.front());
- buy.erase(buy.begin());
- sort(play[it+direc].begin(), play[it+direc].end(), way);
- break;
- case 1: play[it+direc].push_back(buy.front());
- buy.erase(buy.begin());
- sort(play[it+direc].begin(), play[it+direc].end(), way);
- break;
- case 11: break;
- default: if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
- desc = play[it].front();
- play[it].erase(play[it].begin());
- if(!play[it].size()){
- zerou = 1;
- }
- }else{
- play[it].push_back(buy.front());
- buy.erase(buy.begin());
- sort(play[it].begin(), play[it].end(), way);
- if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
- desc = play[it].front();
- play[it].erase(play[it].begin());
- }
- }
- }
- if(zerou){
- break;
- }
- it += direc;
- if(it>x){
- it = 0;
- }else if(it<0){
- it = x;
- }
- }
- cout << it+1 << '\n';
- cin >> p >> m >> n;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment