Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace Orders
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] name = Console.ReadLine().Split(", ").ToArray();
- string namePattern = @"[A-Za-z]";
- string racePattern = @"\d";
- string race = string.Empty;
- string currentName = string.Empty;
- List<string> newWin = new List<string>();
- var winner = new Dictionary<string, int>();
- while ((race = Console.ReadLine()) != "end of race")
- {
- MatchCollection nameRegex = Regex.Matches(race, namePattern);
- MatchCollection raceRegex = Regex.Matches(race, racePattern);
- string newName = string.Empty;
- foreach (Match match in nameRegex)
- {
- newName += match.Value;
- }
- int kilom = 0;
- for (int i = 0; i < name.Length; i++)
- {
- currentName = name[i];
- if (currentName == newName)
- {
- foreach (Match racec in raceRegex)
- {
- kilom += int.Parse(racec.Value);
- }
- if (!winner.ContainsKey(newName))
- {
- winner.Add(newName, kilom);
- }
- else
- {
- winner[newName] += kilom;
- }
- }
- }
- }
- var order = winner.OrderByDescending(x => x.Value);
- for (int j = 0; j < 3; j++)
- {
- foreach (var kvp in order)
- {
- newWin.Add(kvp.Key);
- }
- }
- for (int k = 0; k < 3; k++)
- {
- if (k == 0)
- {
- Console.WriteLine($"{k + 1}st place: {newWin[k]}");
- }
- else if (k == 1)
- {
- Console.WriteLine($"{k + 1}nd place: {newWin[k]}");
- }
- else
- {
- Console.WriteLine($"{k + 1}rd place: {newWin[k]}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement