Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ITCareer_OOP_Exam_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- //до получаване на End of season -> четем стринг
- string input = Console.ReadLine();
- Dictionary<string, int> players = new Dictionary<string, int>();
- while (input != "End of season")
- {
- //"Simo - 2" -> ["Simo", "-", "2"] -> "Simo" и 2
- string name = input.Split(" ")[0];
- int goals = int.Parse(input.Split(" ")[2]);
- //!!!!! 1. проверка дали този ключ вече го има
- if (players.ContainsKey(name))
- {
- players[name] = players[name] + goals;
- }
- else
- {
- players.Add(name, goals);
- }
- input = Console.ReadLine();
- }
- var sortedPlayers = players.OrderBy(pair => pair.Key);
- foreach (var pair in sortedPlayers)
- {
- Console.WriteLine($"{pair.Key} -> {pair.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement