albnayem

Contest Problem F

Jan 29th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. //STL Contest Problem G.
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int main ()
  5. {
  6.     int x;
  7.     while (1)
  8.     {
  9.         cin>>x;
  10.         int arr[x-1];
  11.         if (x==0) break;
  12.  
  13.         queue <int> myQ;
  14.         for (int i=0;i<x;i++)
  15.         {
  16.             myQ.push(i+1);
  17.         }
  18.         cout<<"Discarded cards: ";
  19.  
  20.         while (myQ.size()!=1)
  21.         {
  22.             if (myQ.size()==2) cout<<myQ.front()<<endl;
  23.             else cout<<myQ.front()<<", ";
  24.             myQ.pop();
  25.             int qi=myQ.front();
  26.             myQ.push(qi);
  27.             myQ.pop();
  28.         }
  29.         cout<<"Remaining card: "<<myQ.front()<<endl;
  30.     }
  31.  
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment