desislava_topuzakova

04. Basketball Season

Mar 28th, 2021
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Arrays
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.            
  11.         {
  12.             Dictionary<string, int> players = new Dictionary<string, int>();
  13.             string input = Console.ReadLine();
  14.  
  15.             while (input != "END")
  16.             {
  17.  
  18.                 //"Simona - 20" -> split(" - ") -> ["Simona", "20"]
  19.                 string name = input.Split(" - ")[0]; //Simona
  20.                 int points = int.Parse(input.Split(" - ")[1]); //"20" -> 20
  21.  
  22.                 if(players.ContainsKey(name))
  23.                 {
  24.                     int currentPoints = players[name];
  25.                     players[name] = currentPoints + points;
  26.                 }
  27.                 else
  28.                 {
  29.                     //добавяме го с точките му
  30.                     players.Add(name, points);
  31.                 }
  32.  
  33.                 input = Console.ReadLine();
  34.             }
  35.  
  36.             var ordered = players.OrderBy(pair => pair.Key);
  37.  
  38.             foreach (var pair in ordered)
  39.             {
  40.                 //pair -> key:{name}, value:{points}
  41.                 Console.WriteLine(pair.Key + " -> " + pair.Value );
  42.             }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.         }        
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment