Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 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, List<string>> contestantsByCountry = new Dictionary<string, List<string>>();
  12.             Dictionary<string, int> contestantsByPoints = new Dictionary<string, int>();
  13.             while (true)
  14.             {
  15.                 string input = Console.ReadLine();
  16.                 if (input == "END")
  17.                 {
  18.                     break;
  19.                 }
  20.  
  21.                 string[] contestantInput = input.Split(" -> ");
  22.                 string contestantCounrty = contestantInput[0];
  23.                 string contestantName = contestantInput[1];
  24.                 int contestantPoints = int.Parse(contestantInput[2]);
  25.  
  26.                 if (!contestantsByCountry.ContainsKey(contestantCounrty))
  27.                 {
  28.                     contestantsByCountry[contestantCounrty] = new List<string>();
  29.                 }
  30.  
  31.                 if (!contestantsByCountry[contestantCounrty].Contains(contestantName))
  32.                 {
  33.                     contestantsByCountry[contestantCounrty].Add(contestantName);
  34.                     contestantsByPoints[contestantName] = 0;
  35.                 }
  36.  
  37.                 contestantsByPoints[contestantName] += contestantPoints;
  38.             }
  39.  
  40.             int SumContestantsPoints(KeyValuePair<string, List<string>> cty)
  41.             {
  42.                 int points = 0;
  43.                 foreach (var contestant in cty.Value)
  44.                 {
  45.                     points += contestantsByPoints[contestant];
  46.                 }
  47.  
  48.                 return points;
  49.             }
  50.  
  51.             foreach (var country in contestantsByCountry.OrderByDescending(SumContestantsPoints))
  52.             {
  53.                 Console.WriteLine($"{country.Key}: {SumContestantsPoints(country)}");
  54.                 foreach (var contestant in country.Value)
  55.                 {
  56.                     Console.WriteLine($" -- {contestant} -> {contestantsByPoints[contestant]}");
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement