Advertisement
vov44k

50

Nov 27th, 2022
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. import javax.management.Query;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) throws FileNotFoundException {
  7. //        Scanner scanner = new Scanner(System.in);
  8.         Scanner in = new Scanner(new File("input.txt"));
  9.         PrintWriter pw = new PrintWriter("output.txt");
  10.  
  11.         Queue<Integer> first = new LinkedList<>();
  12.         Queue<Integer> second = new LinkedList<>();
  13.         for (int i = 0; i < 5; i++) {
  14.             first.add(in.nextInt());
  15.         }
  16.         for (int i = 0; i < 5; i++) {
  17.             second.add(in.nextInt());
  18.         }
  19.         int counter = 0;
  20.  
  21.         while (first.size() != 0 && second.size() != 0 && counter <= 1000000) {
  22.             counter++;
  23.             int first_card = first.poll();
  24.             int second_card = second.poll();
  25.             if (first_card == 0 && second_card == 9) {
  26.                 first.add(first_card);
  27.                 first.add(second_card);
  28.                 continue;
  29.             } else if (second_card == 0 && first_card == 9) {
  30.                 second.add(first_card);
  31.                 second.add(second_card);
  32.                 continue;
  33.             }
  34.  
  35.  
  36.             if (first_card > second_card) {
  37.                 first.add(first_card);
  38.                 first.add(second_card);
  39.             } else {
  40.                 second.add(first_card);
  41.                 second.add(second_card);
  42.             }
  43.  
  44.         }
  45.         if (counter > 1000000) {
  46.             pw.println("botva");
  47.             return;
  48.         }
  49.         if (first.size() == 0) {
  50.             pw.println("second" + " " + counter);
  51.         } else {
  52.             pw.println("first" + " " + counter);
  53.         }
  54.  
  55.         in.close();
  56.         pw.close();
  57.  
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement