CSES - Datatähti 2016 alku - Results
Submission details
Task:Osajono
Sender:Galax
Submission time:2015-09-30 22:55:05 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/Main.java:11: error: cannot find symbol
        String un = io.nextLine();
                      ^
  symbol:   method nextLine()
  location: variable io of type IO
input/Main.java:29: error: cannot find symbol
        String mas = io.nextLine();
                       ^
  symbol:   method nextLine()
  location: variable io of type IO
2 errors

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<>();
        String un = io.nextLine();
        String temp = "";
        int pos = 0;
        for (int i = 0; i < un.length(); i++) {
            if (un.charAt(i)==' ') {
                uo.put(pos,Integer.parseInt(temp));
                temp = "";
                pos++;
            } else {
                temp+=un.charAt(i);
            }

        }
        uo.put(books-1,Integer.parseInt(temp));

        temp = "";
        pos = 0;
        HashMap<Integer, Integer> ma = new HashMap<>();
        String mas = io.nextLine();
        for (int i = 0; i < mas.length(); i++) {
            if (mas.charAt(i)==' ') {
                ma.put(pos,Integer.parseInt(temp));
                temp = "";
                pos++;
            } else {
                temp+=mas.charAt(i);
            }

        }
        ma.put(books-1,Integer.parseInt(temp));



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

        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();
    }
}