Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Race
- {
- class Program
- {
- static void Main()
- {
- string[] names = Console.ReadLine()
- .Split(", ")
- .ToArray();
- Dictionary<string, int> racers = new Dictionary<string, int>();
- for (int i = 0; i < names.Length; i++)
- {
- racers.Add(names[i], 0);
- }
- string racerInfo = Console.ReadLine();
- while (racerInfo != "end of race")
- {
- string pattern = @"(?<name>[A-Za-z]+)|(?<distance>\[0-9])";
- MatchCollection nameDistance = Regex.Matches(racerInfo, pattern);
- string name = "";
- foreach (Match item in nameDistance)
- {
- name += item.Groups["name"].Value;
- }
- int splitDigits = 0;
- foreach (Match item in nameDistance)
- {
- splitDigits += int.Parse(item.Groups["distance"].Value);
- }
- if (racers.ContainsKey(name))
- {
- racers[name] += splitDigits;
- }
- racerInfo = Console.ReadLine();
- }
- foreach (var racer in racers)
- {
- Console.WriteLine($"{racer.Key}: {racer.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement