Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.     int count = 0;
  11.     deque<int> first_person;
  12.     deque<int> second_person;
  13.     for (int i = 0; i < n / 2; i++) {
  14.         int x;
  15.         cin >> x;
  16.         first_person.push_back(x);
  17.     }
  18.     for (int j = 0; j < n / 2; j++) {
  19.         int y;
  20.         cin >> y;
  21.         second_person.push_back(y);
  22.     }
  23.     while (true) {
  24.         count++;
  25.         int a = first_person.front();
  26.         int b = second_person.front();
  27.         first_person.pop_front();
  28.         second_person.pop_front();
  29.         if (a > b) {
  30.             first_person.push_back(a);
  31.             first_person.push_back(b);
  32.         } else {
  33.             first_person.pop_front();
  34.             second_person.push_back(a);
  35.             second_person.push_back(b);
  36.         }
  37.         if (a == 0 && b == n - 1) {
  38.             second_person.push_back(a);
  39.             second_person.push_back(b);
  40.         }
  41.         if (b == 0 && a == n - 1) {
  42.             first_person.push_back(a);
  43.             first_person.push_back(b);
  44.         }
  45.         if (first_person.empty()) {
  46.             cout << "second" << count;
  47.             return 0;
  48.         }
  49.         if (second_person.empty()) {
  50.             cout << "first" << count;
  51.             return 0;
  52.         }
  53.         if (count == 2 * pow(10, 5)) {
  54.             cout << "draw";
  55.             return 0;
  56.         }
  57.     }
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement