bacco

СофтУни Кемп

Feb 4th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2.  
  3. namespace tESt
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var numStudents = int.Parse(Console.ReadLine());
  10.  
  11.             var car = 0;         // >= 5
  12.             var van = 0;         // >=12
  13.             var bus = 0;         // >=25
  14.             var doubleBus = 0;   // >=40
  15.             var train = 0;       // < 40
  16.  
  17.             for (int i = 0; i < numStudents; i++)
  18.             {
  19.                 var numGroup = int.Parse(Console.ReadLine());
  20.  
  21.                 if (numGroup <= 5)
  22.                 {
  23.                     car += numGroup;
  24.                 }
  25.                 else if (numGroup <= 12)
  26.                 {
  27.                     van += numGroup;
  28.                 }
  29.                 else if (numGroup <= 25)
  30.                 {
  31.                     bus += numGroup;
  32.                 }
  33.                 else if (numGroup <= 40)
  34.                 {
  35.                     doubleBus += numGroup;
  36.                 }
  37.  
  38.                 else if (numGroup > 40)
  39.                 {
  40.                     train += numGroup;
  41.                 }
  42.             }
  43.  
  44.             double totalStudents = car + van + bus + doubleBus + train;
  45.  
  46.             var carPorcentage = (car / totalStudents) * 100;
  47.             var vanPorcentage = van / totalStudents * 100;
  48.             var busPorcentage = bus / totalStudents * 100;
  49.             var doubleBusPorcentage = doubleBus / totalStudents * 100;
  50.             var trainPorcentage = train / totalStudents * 100;
  51.  
  52.             Console.WriteLine($"{carPorcentage:f2}%");
  53.             Console.WriteLine($"{vanPorcentage:f2}%");
  54.             Console.WriteLine($"{busPorcentage:f2}%");
  55.             Console.WriteLine($"{doubleBusPorcentage:f2}%");
  56.             Console.WriteLine($"{trainPorcentage:f2}%");
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment