Advertisement
Guest User

FootballSeason

a guest
Mar 24th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5.  
  6. namespace Exercise
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.  
  14.             var dictionary = new Dictionary<string, int>();
  15.  
  16.             while(input != “End of season”)
  17.             {
  18.                var tokens = input.Split(-).ToArray();
  19.                string playerName = tokens[0];
  20.                int goals = int.Parse(tokens[1]);
  21.  
  22.                if(!dictionary.ContainsKey(playerName))
  23.                {
  24.                   dictionary.Add(playerName, goals);
  25.                }
  26.                else
  27.                {
  28.                   dictionary[playerName] += goals;
  29.                }
  30.                
  31.                input = Console.ReadLine();
  32.             }
  33.  
  34.            foreach(var kvp in dictionary.OrderBy(x => x.Key))
  35.            {
  36.              Console.WriteLine($”{kvp.Key} - {kvp.Value})
  37.            }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement