SHARE
TWEET

Untitled

a guest Dec 8th, 2019 67 in 321 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Homework;
  2.  
  3. import java.util.Deque;
  4. import java.util.LinkedList;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner s = new Scanner(System.in);
  11.         Deque <Integer> first = new LinkedList();
  12.         Deque <Integer> second = new LinkedList();
  13.  
  14.         for(int i = 0; i < 5; i++){
  15.             first.add(s.nextInt());
  16.         }
  17.         for(int i = 0; i < 5; i++){
  18.             second.add(s.nextInt());
  19.         }
  20.  
  21.  
  22.         int i = 0;
  23.  
  24.         while(first.peek() != null && second.peek() != null && i < 106){
  25.             if(first.peek() == 0 && second.peek() == 9) {
  26.                 first.addLast(first.poll());
  27.                 first.addLast(second.poll());
  28.                 i++;
  29.             }
  30.             else if(first.peek() == 9 && second.peek() == 0) {
  31.                 second.addLast(second.poll());
  32.                 second.addLast(first.poll());
  33.                 i++;
  34.             }
  35.             else if(first.peek() > second.peek()){
  36.                 first.addLast(first.poll());
  37.                 first.addLast(second.poll());
  38.                 i++;
  39.             }
  40.             else {
  41.                 second.addLast(second.poll());
  42.                 second.addLast(first.poll());
  43.                 i++;
  44.             }
  45.         }
  46.  
  47.         if(first.peek() == null)
  48.         {
  49.             System.out.println("second " + i);
  50.         }
  51.         else if(second.peek() == null)
  52.         {
  53.             System.out.println("first " + i);
  54.         }
  55.         else{
  56.             System.out.println("None");
  57.         }
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top