Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n;
- while((cin>>n) && n!=0)
- {
- queue<int>Q,Q1;
- for(int i=1; i<=n; i++)
- {
- Q.push(i);
- }
- while(1)
- {
- if(Q.size()==1)
- break;
- int p = Q.front();
- Q.pop();
- Q1.push(p);
- int q = Q.front();
- Q.pop();
- Q.push(q);
- }
- int i=0;
- cout<<"Discarded cards:";
- while (!Q1.empty())
- {
- if(i==0)
- cout<<Q1.front();
- else
- cout <<", "<< Q1.front();
- Q1.pop();
- i++;
- }
- cout<<endl;
- cout<<"Remaining card:";
- while (!Q.empty())
- {
- cout << ' ' << Q.front();
- Q.pop();
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement