Advertisement
gospod1978

Final Exam/Arriving in Kathmandu

Oct 23rd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace fundamental14
  8. {
  9.     class MainClass
  10.     {
  11.         public static void Main()
  12.         {
  13.             string input = string.Empty;
  14.             string pattern = @"^([A-Za-z0-9\!\@\#\$\?]+)=(\d+)<<([A-Za-z0-9]+)$";
  15.  
  16.             while ((input = Console.ReadLine()) != "Last note")
  17.             {
  18.                 Match match = Regex.Match(input, pattern);
  19.  
  20.                 if (match.Success)
  21.                 {
  22.                     string name = match.Groups[1].Value;
  23.                     int lenght = int.Parse(match.Groups[2].Value);
  24.                     string geohasCode = match.Groups[3].Value;
  25.  
  26.                     if (lenght == geohasCode.Length)
  27.                     {
  28.                         var nameOfMountain = new String(name.Where(Char.IsLetterOrDigit).ToArray());
  29.  
  30.                         Console.WriteLine($"Coordinates found! {nameOfMountain} -> {geohasCode}");
  31.                     }
  32.                     else
  33.                     {
  34.                         Console.WriteLine("Nothing found!");
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.WriteLine("Nothing found!");
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement