Advertisement
gospod1978

Exam\The Isle of Man TT Race 01

Oct 16th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Text.RegularExpressions;
  8.  
  9.  
  10. namespace Orders
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             bool coordinatesFound = false;
  17.  
  18.             while (!coordinatesFound)
  19.             {
  20.                 string input = Console.ReadLine();
  21.  
  22.                 string lengthPattern = @"=(\d+)!!";
  23.  
  24.                 Match number = Regex.Match(input, lengthPattern);
  25.                 if (number.Success)
  26.                 {
  27.                     int length = int.Parse(number.Groups[1].Value);
  28.  
  29.                     string pattern = $@"([#$%*&])(\w+)\1=(\d+)!!(.{{{length}}})$";
  30.  
  31.                     Match match = Regex.Match(input, pattern);
  32.  
  33.                     if (match.Success)
  34.                     {
  35.                         coordinatesFound = true;
  36.                         string name = match.Groups[2].Value;
  37.                         string coord = match.Groups[4].Value;
  38.                         StringBuilder sb = new StringBuilder();
  39.  
  40.                         for (int i = 0; i < coord.Length; i++)
  41.                         {
  42.                             sb.Append((char)(coord[i] + coord.Length));
  43.                         }
  44.  
  45.                         Console.WriteLine($"Coordinates found! {name} -> {sb}");
  46.                         break;
  47.                     }
  48.                     //Console.WriteLine(length);           
  49.                 }
  50.                 Console.WriteLine("Nothing found!");
  51.             }
  52.  
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement