Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _01._The_Isle_of_Man_TT_Race
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {        
  10.             while (true)
  11.             {
  12.                 string input = Console.ReadLine();
  13.                 string regex = @"^([#$%*&])(?<racer>[A-Za-z]+)([#$%*&])=(?<length>[0-9]+)!!(?<geohashCode>.*)";
  14.                 MatchCollection matched = Regex.Matches(input, regex);
  15.  
  16.                 if (matched.Count == 0)
  17.                 {
  18.                     Console.WriteLine("Nothing found!");
  19.                 }
  20.  
  21.                 foreach (Match m in matched)
  22.                 {
  23.                     var racer = m.Groups["racer"].Value;
  24.                     var length = m.Groups["length"].Value;
  25.                     var geohashCode = m.Groups["geohashCode"].Value;
  26.                     if (Convert.ToInt32(length) != geohashCode.Length || m.Groups[1].Value != m.Groups[2].Value)
  27.                     {
  28.                         Console.WriteLine("Nothing found!");
  29.                     }
  30.                     else
  31.                     {
  32.                         string newCode = "";
  33.                         for (int i = 0; i < geohashCode.Length; i++)
  34.                         {
  35.                             newCode += (char)(Convert.ToUInt16(geohashCode[i]) + Convert.ToInt32(length));
  36.                              
  37.                         }
  38.                         Console.WriteLine($"Coordinates found! {racer} -> {newCode}");
  39.                     }                
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement