Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace InternationalSoftUniada
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {            
  11.             Dictionary<string, Dictionary<string, int>> contestantsByCountry = new Dictionary<string, Dictionary<string, int>>();
  12.             while (true)
  13.             {
  14.                 string input = Console.ReadLine();
  15.                 if (input == "END")
  16.                 {
  17.                     break;
  18.                 }
  19.              
  20.                 string[] contestantInput = input.Split(" -> ");
  21.                 string contestantCounrty = contestantInput[0];
  22.                 string contestantName = contestantInput[1];
  23.                 int contestantPoints = int.Parse(contestantInput[2]);
  24.              
  25.                 if (!contestantsByCountry.ContainsKey(contestantCounrty))
  26.                 {
  27.                     contestantsByCountry[contestantCounrty] = new Dictionary<string, int>();
  28.                 }
  29.              
  30.                 if (!contestantsByCountry[contestantCounrty].ContainsKey(contestantName))
  31.                 {
  32.                     contestantsByCountry[contestantCounrty][contestantName] = 0;
  33.                 }
  34.              
  35.                 contestantsByCountry[contestantCounrty][contestantName] += contestantPoints;
  36.             }
  37.            
  38.             foreach (var (country, contestants) in contestantsByCountry.OrderByDescending(cty => cty.Value.Sum(c => c.Value)))
  39.             {
  40.                 Console.WriteLine($"{country}: {contestants.Sum(c => c.Value)}");
  41.                 foreach (var (name, points) in contestants)
  42.                 {
  43.                     Console.WriteLine($" -- {name} -> {points}");
  44.                 }
  45.  
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement