Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Arrays
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> players = new Dictionary<string, int>();
- string input = Console.ReadLine();
- while (input != "END")
- {
- //"Simona - 20" -> split(" - ") -> ["Simona", "20"]
- string name = input.Split(" - ")[0]; //Simona
- int points = int.Parse(input.Split(" - ")[1]); //"20" -> 20
- if(players.ContainsKey(name))
- {
- int currentPoints = players[name];
- players[name] = currentPoints + points;
- }
- else
- {
- //добавяме го с точките му
- players.Add(name, points);
- }
- input = Console.ReadLine();
- }
- var ordered = players.OrderBy(pair => pair.Key);
- foreach (var pair in ordered)
- {
- //pair -> key:{name}, value:{points}
- Console.WriteLine(pair.Key + " -> " + pair.Value );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment