Advertisement
Spocoman

03. Logistics

Dec 25th, 2021 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Logistics(input) {
  2.     let cargoCount = Number(input[0]);
  3.     let bus = 0.0;
  4.     let truck = 0.0;
  5.     let train = 0.0;
  6.     let totalCargo = 0.0;
  7.  
  8.     for (let i = 1; i <= cargoCount; i++) {
  9.         let cargo = Number(input[i]);
  10.         if (cargo < 4) {
  11.             bus += cargo;
  12.         } else if (cargo < 12) {
  13.             truck += cargo;
  14.         } else {
  15.             train += cargo;
  16.         }
  17.         totalCargo += cargo;
  18.     }
  19.  
  20.     let average = (bus * 200 + truck * 175 + train * 120) / totalCargo;
  21.  
  22.     console.log(average.toFixed(2));
  23.     console.log(`${(bus / totalCargo * 100).toFixed(2)}%`);
  24.     console.log(`${(truck / totalCargo * 100).toFixed(2)}%`);
  25.     console.log(`${(train / totalCargo * 100).toFixed(2)}%`);
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement