Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Race
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> racers = Console.ReadLine()
- .Split(", ")
- .ToHashSet()
- .ToDictionary(key => key, value => 0);
- string command;
- while ((command = Console.ReadLine()) != "end of race")
- {
- string racer = Regex.Replace(command, @"[^a-zA-Z]+", "");
- int sum = Regex.Replace(command, @"\D+", "")
- .ToCharArray()
- .Select(x => x - 48)
- .Sum();
- if (racers.ContainsKey(racer))
- {
- racers[racer] += sum;
- }
- }
- int index = 0;
- var placeNum = new[] { "1st", "2nd", "3rd" };
- foreach (var racer in racers.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"{placeNum[index]} place: {racer.Key}");
- if (index == 2)
- {
- break;
- }
- index++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement