Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApp8
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> racers = new Dictionary<string, int>();
- string[] names = Console.ReadLine().Split(", ").ToArray();
- while (true)
- {
- string input = Console.ReadLine();
- if(input== "end of race")
- {
- break;
- }
- StringBuilder word = new StringBuilder();
- int distance = 0;
- for (int i = 0; i < input.Length; i++)
- {
- char letterOrDigit = input[i];
- if (char.IsLetter(letterOrDigit))
- {
- word.Append(letterOrDigit);
- }
- else if (char.IsDigit(letterOrDigit))
- {
- distance += letterOrDigit- '0';
- }
- }
- string name = word.ToString();
- if (!names.Contains(name))
- {
- continue;
- }
- if (racers.ContainsKey(name))
- {
- racers[name] += distance;
- }
- else
- {
- racers[name] = distance;
- }
- }
- int counter = 1;
- foreach (var item in racers.OrderByDescending(x => x.Value))
- {
- if (counter == 1)
- {
- Console.WriteLine($"1st place: {item.Key}");
- }
- else if (counter == 2)
- {
- Console.WriteLine($"2nd place: {item.Key}");
- }
- else if (counter == 3)
- {
- Console.WriteLine($"3rd place: {item.Key}");
- }
- else
- {
- break;
- }
- counter++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement