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;
- namespace _2.Race
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine()
- .Split(", ");
- Dictionary<string, int> racers = new Dictionary<string, int>();
- for (int i = 0; i < input.Length; i++)
- {
- racers[input[i]] = 0;
- }
- StringBuilder sb = new StringBuilder();
- int km = 0;
- while (true)
- {
- string input2 = Console.ReadLine();
- if (input2 == "end of race")
- {
- break;
- }
- char[] current = input2.ToCharArray();
- for (int i = 0; i < current.Length; i++)
- { char now = current[i];
- if (char.IsLetterOrDigit(now))
- { if (char.IsLetter(now))
- { sb.Append(now); }
- if (char.IsDigit(now))
- { km += now; }
- }
- }
- if (racers.ContainsKey($"{sb}"))
- { racers[$"{sb}"] += km; }
- km = 0;
- sb = new StringBuilder();
- }
- if(racers.Count==1)
- {
- foreach (var item in racers.OrderByDescending(x => x.Value).Take(1))
- {
- Console.WriteLine($"1st place: {item.Key}");
- }
- return;
- }
- if (racers.Count == 2)
- {
- foreach (var item in racers.OrderByDescending(x => x.Value).Take(1))
- {
- Console.WriteLine($"1st place: {item.Key}");
- }
- foreach (var item in racers.OrderByDescending(x => x.Value).Skip(1).Take(1))
- {
- Console.WriteLine($"2nd place: {item.Key}");
- }
- return;
- }
- if (racers.Count <= 0)
- { return; }
- foreach (var item in racers.OrderByDescending(x=>x.Value).Take(1))
- {
- Console.WriteLine($"1st place: {item.Key}");
- }
- foreach (var item in racers.OrderByDescending(x => x.Value).Skip(1).Take(1))
- {
- Console.WriteLine($"2nd place: {item.Key}");
- }
- foreach (var item in racers.OrderByDescending(x => x.Value).Skip(2).Take(1))
- {
- Console.WriteLine($"3rd place: {item.Key}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement