Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PCGameShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- int volume = int.Parse(Console.ReadLine());
- double hearthstones = 0,
- fornites = 0,
- overwatches = 0,
- others = 0;
- for (int i = 0; i < volume; i++)
- {
- string game = Console.ReadLine();
- switch (game)
- {
- case "Hearthstone":
- hearthstones++;
- break;
- case "Fornite":
- fornites++;
- break;
- case "Overwatch":
- overwatches++;
- break;
- default:
- others++;
- break;
- }
- }
- Console.WriteLine($"Hearthstone - { hearthstones / volume * 100:F2}%");
- Console.WriteLine($"Fornite - { fornites / volume * 100:F2}%");
- Console.WriteLine($"Overwatch - { overwatches / volume * 100:F2}%");
- Console.WriteLine($"Others - { others / volume * 100:F2}%");
- }
- }
- }
- РЕШЕНИЕ С РЕЧНИК, ТЕРНАРЕН ОПЕРАТОР И FOREACH:
- using System;
- using System.Collections.Generic;
- namespace PCGameShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, double> games = new Dictionary<string, double>() {
- { "Hearthstone", 0 }, { "Fornite", 0 }, { "Overwatch", 0 }, { "Others", 0 }
- };
- int volume = int.Parse(Console.ReadLine());
- for (int i = 0; i < volume; i++)
- {
- string game = Console.ReadLine();
- games[games.ContainsKey(game) ? game : "Others"]++;
- }
- foreach (var game in games)
- {
- Console.WriteLine($"{game.Key} - { game.Value / volume * 100:F2}%");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement