Code Submission Evaluation System Login

Datatähti 2016 alku

Start:2015-09-28 00:00:00
End:2015-10-12 00:00:00
 

Tasks | Scoreboard | Statistics


CSES - Datatähti 2016 alku - Results
History
2015-09-30 23:05:05100
2015-09-30 23:03:090
2015-09-30 23:01:520
2015-09-30 23:01:04
2015-09-30 23:00:050
2015-09-30 22:55:500
2015-09-30 22:54:39
2015-09-30 22:51:240
2015-09-30 22:50:3643
2015-09-30 22:49:3843
2015-09-30 22:49:0443
2015-09-30 22:48:2643
2015-09-30 22:47:4643
2015-09-30 22:47:22
2015-09-30 22:46:0743
2015-09-30 21:35:190
2015-09-30 21:34:150
2015-09-30 21:33:56
2015-09-30 21:30:5543
2015-09-30 21:29:490
2015-09-30 21:28:220
2015-09-30 21:18:410
2015-09-30 14:24:110
2015-09-30 14:15:370
2015-09-30 14:02:1143
2015-09-30 14:01:0543
2015-09-30 14:00:2243
2015-09-30 13:57:270
2015-09-30 13:56:420
2015-09-30 13:55:3743
2015-09-30 13:54:3643
2015-09-30 13:53:0443
2015-09-30 13:37:2043
2015-09-30 13:35:310
2015-09-30 13:32:090
2015-09-30 13:29:580
2015-09-30 13:25:3843
2015-09-30 13:23:400
2015-09-30 13:22:460
2015-09-30 13:21:260
2015-09-30 13:17:410
2015-09-30 13:13:510
2015-09-30 13:10:3043
2015-09-30 13:06:1043
2015-09-30 13:04:310
2015-09-30 13:03:420
2015-09-30 12:53:070
2015-09-30 12:49:270
2015-09-30 12:47:430
2015-09-30 12:38:140
2015-09-30 12:37:390
2015-09-30 12:36:510
2015-09-30 12:35:210
2015-09-30 12:13:270
2015-09-30 11:07:270
2015-09-30 10:56:150
2015-09-29 22:57:290
2015-09-29 22:47:560
2015-09-29 22:10:440
Task:Kirjat
Sender:Galax
Submission time:2015-09-30 22:47:22
Language:Java
Status:COMPILE ERROR

Compiler report

input/Main.java:71: error: variable declaration not allowed here
              int c = 0/0;
                  ^
1 error

Code

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

public class Main {
    public static void main(String[] args) {
        Scanner io = new Scanner(System.in);
        int books = Integer.parseInt(io.nextLine());

        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 (i>1000)
              int c = 0/0;
            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++) {
            System.out.print(end.get(i) + " ");
        }
    }
}