Nathan Coulas

CCC '18 J3 - Are we there yet?

ccc18j3 JAVA8 03 Dec, 2019 0.627s 3 points

Source Code

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");
        }
        
    }
  
    
}