Advertisement
simonradev

Fourth

Apr 30th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Logistics
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int numberOfInputs = int.Parse(Console.ReadLine());
  14.  
  15.             int busCargoInTones = 0;
  16.             int truckCargoInTones = 0;
  17.             int trainCargoInTones = 0;
  18.  
  19.             for (int currInput = 0; currInput < numberOfInputs; currInput++)
  20.             {
  21.                 int cargoTones = int.Parse(Console.ReadLine());
  22.  
  23.                 if (cargoTones <= 3)
  24.                 {
  25.                     busCargoInTones += cargoTones;
  26.                 }
  27.                 else if (cargoTones <= 11)
  28.                 {
  29.                     truckCargoInTones += cargoTones;
  30.                 }
  31.                 else if (cargoTones >= 12)
  32.                 {
  33.                     trainCargoInTones += cargoTones;
  34.                 }
  35.             }
  36.  
  37.             int totalTones = busCargoInTones + truckCargoInTones + trainCargoInTones;
  38.  
  39.             double averagePerTone = ((busCargoInTones * 200.0) +
  40.                                     (truckCargoInTones * 175.0) +
  41.                                     (trainCargoInTones * 120.0)) /
  42.                                     totalTones;
  43.  
  44.             double percentOfCargoForBus = (busCargoInTones / (double)totalTones) * 100;
  45.             double percentOfCargoForTruck = (truckCargoInTones / (double)totalTones) * 100;
  46.             double percentOfCargoForTrain = (trainCargoInTones / (double)totalTones) * 100;
  47.  
  48.             Console.WriteLine($"{averagePerTone:f2}");
  49.             Console.WriteLine($"{percentOfCargoForBus:f2}%");
  50.             Console.WriteLine($"{percentOfCargoForTruck:f2}%");
  51.             Console.WriteLine($"{percentOfCargoForTrain:f2}%");
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement