Solution for CCC '18 J3 - Are we there yet? in Java 8


Dec. 3, 2019 0.627448 seconds Java 8
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
         Scanner in = new Scanner(System.in);
        int[] cities = new int[5];
        for(int i = 0; i < cities.length; i++){
            if(i == 0){
                cities[i] = 0;
            }else{
                cities[i] = in.nextInt();
            }
        }
        
        for(int i = 0; i < cities.length; i++){
            if(i == 0){
                cities[i] = 0;
            }else{
                cities[i] += cities[i - 1];
            }
        }
       
        for(int i = 0; i < 5; i++){
            System.out.print(Math.abs(cities[i] - cities[0]) + " ");
            System.out.print(Math.abs(cities[i] - cities[1]) + " ");
            System.out.print(Math.abs(cities[i] - cities[2]) + " ");
            System.out.print(Math.abs(cities[i] - cities[3]) + " ");
            System.out.print(Math.abs(cities[i] - cities[4]) + " \n");
        }
        
    }
  
    
}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.