Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- int main()
- {
- int t,ile1,ile2,wieksza,tur,c=0;
- cin>>t;
- for(int i=0 ; i<t ; i++)
- {
- cin>>ile1;
- int x;
- stack < int> karty1;
- stack < int> karty2;
- for(int i=0 ; i<ile1 ; i++)
- {
- cin>>x;
- karty1.push(x);
- }
- cin>>ile2;
- for(int i=0 ; i<ile2 ; i++)
- {
- cin>>x;
- karty2.push(x);
- }
- cin>>tur;
- while(karty1.empty()==false && karty2.empty()==false)
- {
- wieksza=max(karty1.top(),karty2.top());
- if(wieksza==karty1.top()){
- karty1.push(karty2.top());
- karty2.pop();
- }
- else if(wieksza==karty2.top()){
- karty2.push(karty1.top());
- karty1.pop();
- }
- if(tur==c) break;
- c++;
- }
- if(karty1.empty()) cout<<"B wygrywa w turze "<< c<<"."<<endl;
- else if(karty2.empty()) cout<<"A wygrywa w turze "<< c<<"."<<endl;
- else {
- cout<<"A:";
- for(int i=0 ; i<karty1.size(); i++)
- {
- cout<<karty1.top();
- karty1.pop();
- }
- cout<<"B:";
- for(int i=0 ; i<karty2.size(); i++)
- {
- cout<<karty2.top();
- karty2.pop();
- }
- }
- c=0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement