Guest User

Untitled

a guest
Feb 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main ()
  4. {
  5.  
  6. int n;
  7. while(cin>>n&&n!=0){
  8. queue<int>q;
  9. vector<int>v;
  10. if(n==1){ cout<<"Discarded cards:"<<endl;cout<<"Remaining card: "<<1<<endl;}
  11. else {
  12. for(int i=1;i<=n;i++)q.push(i);
  13. while(q.size()>=2)
  14. {
  15. v.push_back(q.front());
  16. q.pop();
  17. int y=q.front();
  18. q.pop();
  19. q.push(y);
  20. }
  21. cout<<"Discarded cards:";
  22. for(int i=0;i<v.size()-1;i++)
  23. cout<<" "<<v[i]<<",";
  24. cout<<" "<<v[v.size()-1]<<endl;
  25. cout<<"Remaining card: "<<q.front()<<endl;
  26. }
  27. }
  28. return 0;
  29. }
Add Comment
Please, Sign In to add comment