• Source
    1. ///Author : Shohanur Rahaman
    2. ///URI : 1110
    3.  
    4. #include<bits/stdc++.h>
    5. #include<iostream>
    6. #include<cstdio>
    7. #include<vector>
    8.  
    9. using namespace std;
    10.  
    11. int main()
    12. {
    13. int n;
    14. queue <int> myqueue;
    15.  
    16. while(cin>>n){
    17. if(n==0)
    18. break;
    19.  
    20. for(int i=0;i<n;i++){
    21. myqueue.push(i+1);
    22. }
    23.  
    24. int i = myqueue.size();
    25.  
    26. cout<<"Discarded cards: ";
    27.  
    28. while(i!=1){
    29. int dis = myqueue.front();
    30. cout<<dis;
    31. if(i>2){ cout<<", "; }
    32. myqueue.pop();
    33. i--;
    34.  
    35. int top = myqueue.front();
    36. myqueue.push(top);
    37. myqueue.pop();
    38.  
    39. }
    40. cout<<"\n"<<"Remaining card: "<<myqueue.front()<<endl;
    41. myqueue = queue<int>();
    42. }
    43.  
    44.  
    45. return 0;
    46. }
    47.