Rezultati

Up. imeNalogaJezikRezultatČas oddaje
rektifikatorji-2018 Droni Java Se ne prevede 10. maj '18 @ 18:48

Izpis prevajalnika:
Drone.java:1: error: package factory does not exist
import factory.Rand;
              ^
1 error

Ocenjevani program (Drone.java):
import factory.Rand;

import java.util.Random;
import java.util.Scanner;

public class Drone {

    int[] s1 = new int[3];
    int[] e1 = new int[3];
    int[] s2 = new int[3];
    int[] e2 = new int[3];
    int[] d1 = new int[3];
    int[] d2 = new int[3];

    public Drone(){ }

    public void run(){
        Scanner scanner = new Scanner(System.in);

        s1[0] = scanner.nextInt();
        s1[1] = scanner.nextInt();
        s1[2] = scanner.nextInt();
        e1[0] = scanner.nextInt();
        e1[1] = scanner.nextInt();
        e1[2] = scanner.nextInt();

        s2[0] = scanner.nextInt();
        s2[1] = scanner.nextInt();
        s2[2] = scanner.nextInt();
        e2[0] = scanner.nextInt();
        e2[1] = scanner.nextInt();
        e2[2] = scanner.nextInt();

        for(int i = 0; i < 3; i++){
            if(s1[i] < e1[i]) d1[i] = 1;
            else d1[i] = -1;

            if(s2[i] < e2[i]) d2[i] = 1;
            else d2[i] = -1;
        }

        printPosition();

        boolean done = false;
        while (true){
            if(s1[0]==e1[0] && s1[1]==e1[1] && s1[2]==e1[2]  &&  s2[0]==e2[0] && s2[1]==e2[1] && s2[2]==e2[2]){
                break;
            }

            move();
            printPosition();
        }

        printPosition();
    }

    void printPosition(){
        String pos = String.format("(%d %d %d) (%d %d %d)", s1[0],s1[1],s1[2], s2[0],s2[1],s2[2]);
        System.out.println(pos);
    }

    void move(){
        int m1 = -1;
        int m2 = -1;

        // try select chords 1
        for (int i = 0; i < 3; i++){
            if(s1[i] != e1[i]){
                m1 = i;
                break;
            }
        }
        for (int i = 0; i < 3; i++){
            if(s2[i] != e2[i] && i != m1 && m1 != -1){
                m2 = i;
                break;
            }
        }

        // try select chords 2
        if(m1 == -1 && m2 == -1){
            for (int i = 0; i < 3; i++){
                if(s2[i] != e2[i]){
                    m2 = i;
                    break;
                }
            }
            for (int i = 0; i < 3; i++){
                if(s1[i] != e1[i] && i != m2 && m2 != -1){
                    m1 = i;
                    break;
                }
            }
        }

        // move
        if(m1 >= 0){
            s1[m1] += d1[m1];
        }
        if(m2 >= 0){
            s2[m2] += d2[m2];
        }
    }

    public static void main(String[] args) {
        Drone drone = new Drone();
        drone.run();
    }

}