fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fr first
  4. #define endl "\n"
  5. #define sc second
  6. #define sz(x) (int) x.size()
  7. #define pb push_back
  8. #define all(x) x.begin(), x.end()
  9.  
  10. using namespace std;
  11. using pii = pair<ll, ll>;
  12. using tii = tuple<ll, ll, ll>;
  13. string printBin(ll m) { string a = ""; for(int i=63; i>=0; i--) { if(m & (1<<i)) {a += '1';} else {a += '0';} } return a; }
  14.  
  15. int main() {
  16. ios::sync_with_stdio(0); cin.tie(0);
  17.  
  18. int n;
  19.  
  20. while(cin >> n) {
  21. if(n == 0) break;
  22.  
  23. queue<int> q;
  24. vector<int> ans;
  25.  
  26. for(int i=1; i<=n; i++) q.push(i);
  27.  
  28. while(sz(q) >= 2) {
  29. auto ai = q.front();
  30. q.pop();
  31. auto aj = q.front();
  32. q.pop();
  33.  
  34. q.push(aj);
  35.  
  36. ans.pb(ai);
  37. }
  38.  
  39. cout << "Discarded cards: ";
  40. int c = 0;
  41.  
  42. for(auto ai : ans) {
  43. if(c > 0) cout << ", ";
  44. cout << ai;
  45. c++;
  46. }
  47. cout << endl;
  48. cout << "Remaining card: " << q.front() << endl;
  49. }
  50. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty