Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.management.Query;
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException {
- // Scanner scanner = new Scanner(System.in);
- Scanner in = new Scanner(new File("input.txt"));
- PrintWriter pw = new PrintWriter("output.txt");
- Queue<Integer> first = new LinkedList<>();
- Queue<Integer> second = new LinkedList<>();
- for (int i = 0; i < 5; i++) {
- first.add(in.nextInt());
- }
- for (int i = 0; i < 5; i++) {
- second.add(in.nextInt());
- }
- int counter = 0;
- while (first.size() != 0 && second.size() != 0 && counter <= 1000000) {
- counter++;
- int first_card = first.poll();
- int second_card = second.poll();
- if (first_card == 0 && second_card == 9) {
- first.add(first_card);
- first.add(second_card);
- continue;
- } else if (second_card == 0 && first_card == 9) {
- second.add(first_card);
- second.add(second_card);
- continue;
- }
- if (first_card > second_card) {
- first.add(first_card);
- first.add(second_card);
- } else {
- second.add(first_card);
- second.add(second_card);
- }
- }
- if (counter > 1000000) {
- pw.println("botva");
- return;
- }
- if (first.size() == 0) {
- pw.println("second" + " " + counter);
- } else {
- pw.println("first" + " " + counter);
- }
- in.close();
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement