Advertisement
hkshakib

Untitled

Mar 16th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. while((cin>>n) && n!=0)
  7. {
  8. queue<int>Q,Q1;
  9. for(int i=1; i<=n; i++)
  10. {
  11. Q.push(i);
  12. }
  13. while(1)
  14. {
  15. if(Q.size()==1)
  16. break;
  17. int p = Q.front();
  18. Q.pop();
  19. Q1.push(p);
  20. int q = Q.front();
  21. Q.pop();
  22. Q.push(q);
  23. }
  24. int i=0;
  25. cout<<"Discarded cards:";
  26. while (!Q1.empty())
  27. {
  28. if(i==0)
  29. cout<<Q1.front();
  30. else
  31. cout <<", "<< Q1.front();
  32. Q1.pop();
  33. i++;
  34. }
  35. cout<<endl;
  36. cout<<"Remaining card:";
  37. while (!Q.empty())
  38. {
  39. cout << ' ' << Q.front();
  40. Q.pop();
  41. }
  42. cout<<endl;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement