Advertisement
vencinachev

Presents-2

Nov 21st, 2021
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int children = int.Parse(Console.ReadLine());
  10.             int lego = 0, puzzle = 0, robots = 0, monopoly = 0;
  11.             for (int i = 0; i < children; i++)
  12.             {
  13.                 string toy = Console.ReadLine();
  14.                 switch (toy)
  15.                 {
  16.                     case "lego": lego++; break;
  17.                     case "robot": robots++; break;
  18.                     case "monopoly": monopoly++; break;
  19.                     case "puzzle": puzzle++; break;
  20.                 }
  21.             }
  22.  
  23.             double prLego = (lego * 100.0) / children;
  24.             double prPuzzle = (puzzle * 100.0) / children;
  25.             double prMono = (monopoly * 100.0) / children;
  26.             double prRobot = (robots * 100.0) / children;
  27.  
  28.             Console.WriteLine($"Lego: {prLego:F2}%");
  29.             Console.WriteLine($"Monopoly: {prMono:F2}%");
  30.             Console.WriteLine($"Puzzles: {prPuzzle:F2}%");
  31.             Console.WriteLine($"Robots: {prRobot:F2}%");
  32.         }
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement