Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     int t,ile1,ile2,wieksza,tur,c=0;
  9.     cin>>t;
  10.     for(int i=0 ; i<t ; i++)
  11.     {
  12.         cin>>ile1;
  13.         int x;
  14.         stack < int> karty1;
  15.     stack < int> karty2;
  16.          for(int i=0 ; i<ile1 ; i++)
  17.     {
  18.        cin>>x;
  19.        karty1.push(x);
  20.     }
  21.          cin>>ile2;
  22.          for(int i=0 ; i<ile2 ; i++)
  23.     {
  24.         cin>>x;
  25.        karty2.push(x);
  26.     }
  27.     cin>>tur;
  28.      while(karty1.empty()==false && karty2.empty()==false)
  29.      {
  30.          wieksza=max(karty1.top(),karty2.top());
  31.          if(wieksza==karty1.top()){
  32.             karty1.push(karty2.top());
  33.             karty2.pop();
  34.          }
  35.           else if(wieksza==karty2.top()){
  36.             karty2.push(karty1.top());
  37.             karty1.pop();
  38.          }
  39.          if(tur==c) break;
  40.          c++;
  41.  
  42.      }
  43.      if(karty1.empty()) cout<<"B wygrywa w turze "<< c<<"."<<endl;
  44.      else if(karty2.empty()) cout<<"A wygrywa w turze "<< c<<"."<<endl;
  45.      else {
  46.         cout<<"A:";
  47.          for(int i=0 ; i<karty1.size(); i++)
  48.          {
  49.              cout<<karty1.top();
  50.              karty1.pop();
  51.          }
  52.          cout<<"B:";
  53.          for(int i=0 ; i<karty2.size(); i++)
  54.          {
  55.              cout<<karty2.top();
  56.              karty2.pop();
  57.          }
  58.      }
  59.      c=0;
  60.  
  61.     }
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement