CSES - Datatähti 2016 alku - Results
Submission details
Task:Kirjat
Sender:testUser
Submission time:2015-10-05 14:25:55 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/Kirjat.java:20: error: unmappable character for encoding UTF8
        //ohjataan toisen rivin arvot vastaamaan sen ylapuolella olevaa arvoa ja toisin p?in
                                                                                         ^
1 error

Code

/**
 * Created by Frans on 04/10/2015.
 */
import java.util.*;


public class Kirjat {
    public static void main(String[] args){
        IO io = new IO();

        int amount = io.nextInt();

        int[] mainRow = new int[amount+1];
        int[] secondRow = new int[amount+1];

        for (int i = 1; i <= amount; i++){
            mainRow[i] = io.nextInt();
        }

        //ohjataan toisen rivin arvot vastaamaan sen ylapuolella olevaa arvoa ja toisin päin
        int[] mainValue = new int[amount+1];
        int[] invertSecond = new int[amount+1];

        for (int i = 1; i <= amount; i++) {
            secondRow[i] = io.nextInt();
            mainValue[secondRow[i]] = mainRow[i];
        }


        //1. rivin jarjestyksessa
        for (int i = 1; i <= amount; i++) {
            int a = mainRow[i];
            if (mainValue[a] == secondRow[i]) {
                //io.println("B");
                int x = 1;
                int tmpValue = mainValue[a];
                while (true) {
                    int y = ((i + x) % amount)+1;

                    /*System.out.println("a: " + a);
                    System.out.println("y: " + y);
                    System.out.println("value: " + tmpValue);
                    System.out.println("second: " + secondRow[y]);
                    System.out.println("value2: " + mainValue[mainRow[y]]);
                    System.out.println("second2: " + secondRow[i]);
                    */

                    //Swap
                    if (tmpValue != secondRow[y]
                            && tmpValue != mainRow[y]
                            && mainValue[mainRow[y]] != mainRow[i]
                            && mainValue[mainRow[y]] != secondRow[i]) {
                        mainValue[a] = mainValue[mainRow[y]];
                        mainValue[mainRow[y]] = tmpValue;
                        //System.out.println("JEE");
                        break;
                    }
                    x++;
                }

            }
            //io.println("A");
        }


        for (int i = 1; i <= amount; i++) {
            int a = mainRow[i];
            io.println(mainValue[a]);
        }

        io.close();
    }
}