Jeremiah_

Bora_Bora - Neps Academy

Mar 20th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <stdio.h>
  4. #include <stack>
  5. #include <list>
  6. #include <vector>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <iostream>
  10. #include <iomanip>
  11. #include <string.h>
  12. #include <sstream>
  13. #include <bitset>
  14.  
  15. using namespace std;
  16.  
  17. struct card{
  18.     int val;
  19.     char nipe;
  20. };
  21. typedef struct card Card;
  22.  
  23. bool way(Card a, Card b) {
  24.     if(a.val == b.val){
  25.         if(a.nipe == 'C'){
  26.             return 0;
  27.         }else if(a.nipe == 'D'){
  28.             if(b.nipe == 'C') return 1;
  29.             return 0;
  30.         }else if(a.nipe == 'H'){
  31.             if(b.nipe == 'S') return 0;
  32.             return 1;
  33.         }return 1;
  34.     }
  35.     return a.val > b.val;}
  36.  
  37.  
  38.  
  39. int main(){
  40.    
  41.     int p, m, n;
  42.    
  43.     cin >> p >> m >> n;
  44.     while((p+m+n)){
  45.     vector<Card> play[12];
  46.     vector<Card> buy;
  47.     Card desc;
  48.  
  49.     for(int i=0; i<p; ++i){
  50.         for(int j=0; j<m; ++j){
  51.             Card c;
  52.             cin >> c.val >> c.nipe;
  53.             play[i].push_back(c);
  54.            
  55.         }
  56.     }
  57.     cin >> desc.val >> desc.nipe;
  58.     for(int i=p*m+1; i<n; ++i){
  59.         Card c;
  60.         cin >> c.val >> c.nipe;
  61.         buy.push_back(c);  
  62.     }
  63.     int x = p-1;
  64.     while(x--){
  65.         sort(play[x].begin(), play[x].end(), way);
  66.     }
  67.     int it = 0;
  68.     int direc = 1;
  69.     x = p-1;
  70.     int zerou = 0;
  71.     while(true){
  72.         switch(desc.val){
  73.             case 12: direc *= -1;
  74.                 if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
  75.                     desc = play[it].front();
  76.                     play[it].erase(play[it].begin());
  77.                     if(!play[it].size()){
  78.                         zerou = 1;
  79.                     }
  80.                 }else{
  81.                     play[it].push_back(buy.front());
  82.                     buy.erase(buy.begin());
  83.                     sort(play[it].begin(), play[it].end(), way);
  84.                     if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
  85.                         desc = play[it].front();
  86.                         play[it].erase(play[it].begin());
  87.                      }
  88.                 }
  89.                 break;
  90.  
  91.             case 7: play[it+direc].push_back(buy.front());
  92.                 buy.erase(buy.begin());
  93.                 play[it+direc].push_back(buy.front());
  94.                 buy.erase(buy.begin());
  95.                 sort(play[it+direc].begin(), play[it+direc].end(), way);
  96.                 break;
  97.  
  98.             case 1: play[it+direc].push_back(buy.front());
  99.                 buy.erase(buy.begin());
  100.                 sort(play[it+direc].begin(), play[it+direc].end(), way);
  101.                 break;
  102.  
  103.             case 11: break;
  104.            
  105.             default: if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
  106.                     desc = play[it].front();
  107.                     play[it].erase(play[it].begin());
  108.                     if(!play[it].size()){
  109.                         zerou = 1;
  110.                     }
  111.                  }else{
  112.                     play[it].push_back(buy.front());
  113.                     buy.erase(buy.begin());
  114.                     sort(play[it].begin(), play[it].end(), way);
  115.                     if(play[it].front().val == desc.val || play[it].front().nipe == desc.nipe){
  116.                         desc = play[it].front();
  117.                         play[it].erase(play[it].begin());
  118.                      }
  119.                  }
  120.         }
  121.         if(zerou){
  122.             break;
  123.         }
  124.         it += direc;   
  125.         if(it>x){
  126.             it = 0;
  127.         }else if(it<0){
  128.             it = x;
  129.         }
  130.        
  131.     }
  132.     cout << it+1 << '\n';
  133.     cin >> p >> m >> n;
  134.     }
  135.     return 0;
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment