Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int N = 1e6 + 5;
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- long long n;
- int main()
- {
- IO
- while (cin >> n && n)
- {
- deque<long long>dq;
- for (int i = 1; i <= n; i++)
- {
- dq.push_back(i);
- }
- vector<long long>dis;
- while(dq.size() >= 2)
- {
- dis.push_back(dq.front());
- dq.pop_front();
- dq.push_back(dq.front());
- dq.pop_front();
- }
- cout << "Discarded cards:";
- long long sz = dis.size();
- for (int i = 0; i < sz - 1; i++)
- {
- cout << ' ' << dis[i] << ",";
- }
- if (dis.size())cout << ' ' << dis[dis.size() - 1];
- cout << "\n" << "Remaining card: ";
- cout << dq.front() << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment