chillurbrain

18. Игра в пьяницу

May 25th, 2016
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a, c = 0;
  7.     queue<int> f, s;
  8.     for (int i = 0; i < 10; i++) {
  9.         cin >> a;
  10.         if (i < 5) {
  11.             f.push(a);
  12.         }
  13.         else {
  14.             s.push(a);
  15.         }
  16.     }
  17.     while (!f.empty() && !s.empty() && c <= 1000000) {
  18.         if (f.front() == 0 && s.front() == 9) {
  19.             f.push(0);
  20.             f.push(9);
  21.         }
  22.         else {
  23.             if (f.front() == 9 && s.front() == 0) {
  24.                 s.push(9);
  25.                 s.push(0);
  26.             }
  27.             else {
  28.                 if (s.front() > f.front()) {
  29.                     s.push(f.front());
  30.                     s.push(s.front());
  31.                 }
  32.                 else {
  33.                     f.push(f.front());
  34.                     f.push(s.front());
  35.                 }
  36.             }
  37.         }
  38.         s.pop();
  39.         f.pop();
  40.         c++;
  41.     }
  42.     if (c > 1000000) {
  43.         cout << "botva";
  44.     }
  45.     else {
  46.         if (s.empty()) {
  47.             cout << "first";
  48.         }
  49.         else {
  50.             cout << "second";
  51.         }
  52.         cout << " " << c;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment