Mahmoud_Hawara

Untitled

Jul 19th, 2022
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. const long long MOD = 1e9 + 7, OO = 1e18;
  5. const double PI = acos(-1);
  6. const int N = 1e6 + 5;
  7. const int dx[4] = {0, 0, 1, -1};
  8. const int dy[4] = {1, -1, 0, 0};
  9.  
  10. long long n;
  11.  
  12. int main()
  13. {
  14.     IO
  15.     while (cin >> n && n)
  16.     {
  17.         deque<long long>dq;
  18.         for (int i = 1; i <= n; i++)
  19.         {
  20.             dq.push_back(i);
  21.         }
  22.         vector<long long>dis;
  23.         while(dq.size() >= 2)
  24.         {
  25.             dis.push_back(dq.front());
  26.             dq.pop_front();
  27.             dq.push_back(dq.front());
  28.             dq.pop_front();
  29.         }
  30.         cout << "Discarded cards:";
  31.         long long sz = dis.size();
  32.         for (int i = 0; i < sz - 1; i++)
  33.         {
  34.             cout << ' ' << dis[i] << ",";
  35.         }
  36.         if (dis.size())cout << ' ' << dis[dis.size() - 1];
  37.         cout << "\n" << "Remaining card: ";
  38.         cout << dq.front() << '\n';
  39.     }
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment