CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:Galax
Submission time:2015-09-30 23:01:04
Language:Java
Status:COMPILE ERROR

Compiler report

input/Main.java:31: error: unreachable statement
        ArrayList<Integer> tempo = new ArrayList<>();
                           ^
1 error

Code

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        IO io = new IO();
        int books = io.nextInt();

        HashMap<Integer, Integer> uo = new HashMap<>();
        int pos = 0;
        for (int i = 0; i < books; i++) {
                uo.put(pos,io.nextInt());
        }

        pos = 0;
        HashMap<Integer, Integer> ma = new HashMap<>();
        for (int i = 0; i < books; i++) {
            ma.put(pos,io.nextInt());
        }



        ArrayList<Integer> end = new ArrayList<>();
        for (int i = 0; i < books; i++) {
            end.add(0);
        }
        while(true){
            pos++;
        }
        ArrayList<Integer> tempo = new ArrayList<>();
        ArrayList<Integer> tempo2 = new ArrayList<>();

        for (int i = 0; i < books; i++) {
            Boolean wasAdded = false;
            for (int j = i; j < books; j++) {
                if (i+1 != ma.get(j) && i+1 != uo.get(j) && end.get(j)==0) {
                    end.set(j, i+1);
                    wasAdded = true;
                    break;
                }
            }
            if (!wasAdded) {
              for (int j = 0; j < i; j++) {
                  if (i+1 != ma.get(j) && i+1 != uo.get(j) && end.get(j)==0) {
                      end.set(j, i+1);
                      wasAdded = true;
                      break;
                  }
              }
            }

            if (!wasAdded) {
                tempo.add(i+1);
            }
        }



        //use hashmaps to remove unused cells from it, use while loop?
        tempo2.add(end.indexOf(0));
        //tempo2 includes the positions of 0 ints
        //tempo includes the values not added
        if (tempo.size()!=0) {
            for (int i = 0; i < books; i++) {
                if((tempo.get(0) != ma.get(i) && tempo.get(0) != uo.get(i))
                        && ma.get(tempo2.get(0)) != end.get(i) && uo.get(tempo2.get(0)) != end.get(i)) {
                        int tem = end.get(i);
                        end.set(i,tempo.get(0));
                        end.set(tempo2.get(0),tem);
                        break;
                }
            }
        }

        for (int i = 0; i < end.size(); i++) {
            io.print(end.get(i) + " ");
        }
        io.close();
    }
}