Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //STL Contest Problem G.
- #include <bits/stdc++.h>
- using namespace std;
- int main ()
- {
- int x;
- while (1)
- {
- cin>>x;
- int arr[x-1];
- if (x==0) break;
- queue <int> myQ;
- for (int i=0;i<x;i++)
- {
- myQ.push(i+1);
- }
- cout<<"Discarded cards: ";
- while (myQ.size()!=1)
- {
- if (myQ.size()==2) cout<<myQ.front()<<endl;
- else cout<<myQ.front()<<", ";
- myQ.pop();
- int qi=myQ.front();
- myQ.push(qi);
- myQ.pop();
- }
- cout<<"Remaining card: "<<myQ.front()<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment