Advertisement
desislava_topuzakova

Untitled

Apr 25th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ITCareer_OOP_Exam_1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. //до получаване на End of season -> четем стринг
  12.  
  13. string input = Console.ReadLine();
  14. Dictionary<string, int> players = new Dictionary<string, int>();
  15.  
  16. while (input != "End of season")
  17. {
  18. //"Simo - 2" -> ["Simo", "-", "2"] -> "Simo" и 2
  19. string name = input.Split(" ")[0];
  20. int goals = int.Parse(input.Split(" ")[2]);
  21.  
  22. //!!!!! 1. проверка дали този ключ вече го има
  23. if (players.ContainsKey(name))
  24. {
  25. players[name] = players[name] + goals;
  26. }
  27. else
  28. {
  29. players.Add(name, goals);
  30. }
  31.  
  32. input = Console.ReadLine();
  33. }
  34.  
  35. var sortedPlayers = players.OrderBy(pair => pair.Key);
  36.  
  37. foreach (var pair in sortedPlayers)
  38. {
  39. Console.WriteLine($"{pair.Key} -> {pair.Value}");
  40. }
  41.  
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement