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

Compiler report

input/Ohjelma.java:6: error: constructor IO in class IO cannot be applied to given types;
        IO io = new IO(System.in);
                ^
  required: no arguments
  found: InputStream
  reason: actual and formal argument lists differ in length
1 error

Code

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

public class Ohjelma {
    public static void main(String[] args) {
        IO io = new IO(System.in);
        int books = Integer.parseInt(io.next());
        
        ArrayList<Integer> uo = new ArrayList<>();
        String un = io.next();
        String temp = "";
        for (int i = 0; i < un.length(); i++) {
            if (un.charAt(i)==' ') {
                uo.add(Integer.parseInt(temp));
                temp = "";
            } else {
                temp+=un.charAt(i);
            }
            
        }
        uo.add(Integer.parseInt(temp));
        temp = "";
        ArrayList<Integer> ma = new ArrayList<>();
        String mas = io.next();
        for (int i = 0; i < mas.length(); i++) {
            if (mas.charAt(i)==' ') {
                ma.add(Integer.parseInt(temp));
                temp = "";
            } else {
                temp+=mas.charAt(i);
            }
            
        }
        ma.add(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 = 0; 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) {
                tempo.add(i+1);
              
            }
            
        }
        for (int i = 0; i < end.size(); i++) {
            if (end.get(i)==0) {
                tempo2.add(i);
            }
        }
        //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) + " ");
        }
    }
}