fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class card {
  6. int f;
  7. int b;
  8. int *arr;
  9. public:
  10. card(int n) {
  11. f = 0;
  12. b = -1;
  13. arr = new int[n];
  14. }
  15. void push(int n) {
  16. arr[++b] = n;
  17. }
  18. int pop() {
  19. if (empty()) return -1;
  20. return arr[f++];
  21. }
  22. int size() {
  23. return b - f + 1;
  24. }
  25. int empty() {
  26. return (b - f) == -1;
  27. }
  28. ~card() {
  29. delete[] arr;
  30. }
  31. };
  32. int main(void)
  33. {
  34. ios_base::sync_with_stdio(false); cin.tie(NULL);
  35. int n;
  36. cin >> n;
  37.  
  38. card q(n * 2);
  39.  
  40. for (int i = 1; i <= n; i++) q.push(i);
  41.  
  42. while (q.size() != 1)
  43. {
  44. q.pop();
  45. q.push(q.pop());
  46. }
  47. cout << q.pop();
  48. }
Success #stdin #stdout 0s 5516KB
stdin
6
stdout
4