alexbancheva

Arriving in Kathmandu_Group 1

Oct 27th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Arriving_In_Kathmandu
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = "";
  11.  
  12.             string patern = @"^(?<nameofpeak>[A-Za-z0-9!@#$?]+)=(?<length>\d+)<<(?<code>(.*?)+)$";
  13.             // ne e moi patern ^(?<nameofpeak>[A-Za-z0-9!@#$?]+)=(?<length>\d+)<<(?<code>(.*?)+)$
  14.  
  15.             // Dictionary<string, string> mountsInfo = new Dictionary<string, string>(); rechnika nqma da mi trqbva zashtto shte pechatam vutre v chikala tei kato iskat postoqno da se otpechatva suobshtenie
  16.             while ((input = Console.ReadLine()) != "Last note")
  17.             {
  18.                 var match = Regex.Match(input, patern);
  19.                 if (match.Success)
  20.                 {
  21.                     string onlyPeakName = "";
  22.  
  23.                     string namePeak = match.Groups["nameofpeak"].Value;
  24.                     int lenght = int.Parse(match.Groups["length"].Value);
  25.                     string cordinate = match.Groups["code"].Value;
  26.  
  27.                     if (cordinate.Length != lenght)
  28.                     {
  29.                         Console.WriteLine("Nothing found!");
  30.                         continue;
  31.                     }
  32.                     else
  33.                     {
  34.                         for (int i = 0; i < namePeak.Length; i++)
  35.                         {
  36.                             char simbol = namePeak[i];
  37.  
  38.                             if (char.IsLetter(simbol))
  39.                             {
  40.                                 onlyPeakName += simbol;
  41.                             }
  42.                         }
  43.                         Console.WriteLine($"Coordinates found! {onlyPeakName} -> {cordinate}");
  44.                     }
  45.  
  46.                    
  47.  
  48.                     //foreach (var item in namePeak)
  49.                     //{
  50.                     //    char simbol = item;
  51.                     //    if (char.IsLetter(simbol))
  52.                     //    {
  53.                     //        onlyPeakName += simbol;
  54.                     //    }
  55.                     //    else if (char.IsDigit(simbol))
  56.                     //    {
  57.                     //        onlyPeakName += (char)(simbol); // izlishno e da go castvam znam :D
  58.                     //    }
  59.                     //}
  60.                     //if (onlyPeakName.Length == lenght || namePeak.Length == lenght || onlyPeakName.Length - 1 == lenght)
  61.                     //{
  62.                     //    Console.WriteLine($"Coordinates found! {onlyPeakName} -> {cordinate}");
  63.                     //}
  64.                     //else
  65.                     //{
  66.                     //    Console.WriteLine("Nothing found!");
  67.                     //}
  68.  
  69.                 }
  70.                 else
  71.                 {
  72.                     Console.WriteLine("Nothing found!");
  73.                 }
  74.             }
  75.         }
  76.     }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment