Advertisement
Spocoman

03. Logistics

Aug 28th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Logistics {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int cargoCount = Integer.parseInt(scanner.nextLine());
  7.         double bus = 0, truck = 0, train = 0, totalCargo = 0;
  8.  
  9.         for (int i = 0; i < cargoCount; i++) {
  10.             double cargo = Double.parseDouble(scanner.nextLine());
  11.             if (cargo < 4) {
  12.                 bus += cargo;
  13.             } else if (cargo < 12) {
  14.                 truck += cargo;
  15.             } else {
  16.                 train += cargo;
  17.             }
  18.             totalCargo += cargo;
  19.         }
  20.  
  21.         double average = (bus * 200 + truck * 175 + train * 120) / totalCargo;
  22.  
  23.         System.out.printf("%.2f\n", average);
  24.         System.out.printf("%.2f%%\n", bus / totalCargo * 100);
  25.         System.out.printf("%.2f%%\n", truck / totalCargo * 100);
  26.         System.out.printf("%.2f%%\n", train / totalCargo * 100);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement