JulianJulianov

[A-z]

Jul 18th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 KB | None | 0 0
  1. Problem 1. The Isle of Man TT Race
  2. This year’s Isle of Man TT Race is going to be around Douglas  and your job is to find the exact coordinates for it and the names of the racers. Every racer starts from a different place. You’re going to receive the coordinates in the form of a geohash code.
  3.  
  4. Write a program that decrypts messages. You’re going to receive a few notes that contain the following information:
  5. • Name of racer
  6. o   Consists only of letters. It is surrounded from the both sides by any of the following symbols – "#, $, %, *, &". Both symbols – in the beginning and at the end of the name should match.
  7. • Length of geohashcode
  8. o   Begins after the "=" sign and it is consisted only of numbers.
  9. • Encrypted geohash code
  10. o   Begins after these symbols -!!. It may contain anything and the message always ends with it.
  11. Examples for valid input:
  12. #SteveHislop#=16!!tv5dekdz8x11ddkc
  13. Examples of invalid input:
  14. %GiacomoAgostini$=7!!tv58ycb – The length is the same, but the name is not surrounded by matching signs.
  15. $GeoffDuke$=6!!tuvz26n35dhe4w4 – The length doesn't match the lengh of the code.
  16. &JoeyDunlop&!!tvndjef67t=14 – The length should be before the code.
  17. The information must be in the given order, otherwise it is considered invalid. The geohash code you are looking for is with length exactly as much as the given length in the message. To decrypt the code you need to increase the value of each symbol from the geohashcode with the given length. If you find a match, you have to print the following message:
  18. "Coordinates found! {nameOfRacer} -> {geohashcode}"
  19. and stop the program. Otherwise, after every invalid message print:
  20. "Nothing found!"
  21. Input / Constraints
  22. • You will be receiving strings.
  23. • There will always be a valid message.
  24. Output
  25. • If you find the right coordinates, print: "Coordinates found! {nameOfRacer} -> {geohashcode}".
  26. • Otherwise, print: "Nothing found!".
  27. Examples
  28. Input                                                      Output
  29. %GiacomoAgostini%=7!!hbqw                                  Nothing found!
  30. &GeoffDuke*=6!!vjh]zi                                      Nothing found!
  31. JoeyDunlop=10!!lkd,rwazdr                                  Nothing found!
  32. Mike??Hailwood=5!![pliu                                    Coordinates found! SteveHislop -> tv5dekdz8x11ddkc
  33. #SteveHislop#=16!!df%TU[Tj(h!!TT[S  Nothing found!
  34. Comments
  35. The first line matches, but the length of the code doesn't match the given number, so we print "Nothing found!"
  36. The second line begins with "&", but ends with "*", so we print "Nothing found!"
  37. The third line is not valid because the name is not surrounded with one of the allowed symbols.
  38. The forth line is not a match, because the name doesn't contain only letters.
  39. The fifth line is a match and the length is equal to the given number - 16, so we increase each of the symbols from the code with 16 and print the message in the appropriate format.
  40.  
  41. Ian6Hutchinson=7!!\(58ycb4                               Nothing found!
  42. #MikeHailwood#!!'gfzxgu6768=11                           Nothing found!
  43. slop%16!!plkdek/.8x11ddkc                                Nothing found!
  44. $Steve$=9Hhffjh                                          Nothing found!
  45. *DavMolyneux*=15!!efgk#'_$&UYV%h%                        Coordinates found! DaveMolyneux -> tuvz26n35dhe4w4
  46. RichardQ^uayle=16!!fr5de5kd Nothing found!
  47. using System;
  48. using System.Text;
  49. using System.Text.RegularExpressions;
  50.  
  51. namespace Final_Exam___14_April_2019_Group_II
  52. {
  53.     class Program
  54.     {
  55.         static void Main(string[] args)
  56.         {
  57.             while (true)//My
  58.             {
  59.                 var messages = Console.ReadLine();
  60.                 var pattern = @"^(#|\$|%|\*|&)(?<Name>[A-z]+)\1=(?<LengthCode>\d+)!!(?<Geohashcode>.+)$";
  61.                 var matchPattern = Regex.Match(messages, pattern);
  62.                 if (matchPattern.Success)
  63.                 {
  64.                     var name = matchPattern.Groups["Name"].Value;
  65.                     var codeLength = int.Parse(matchPattern.Groups["LengthCode"].Value);
  66.                     var geohashCode = matchPattern.Groups["Geohashcode"].Value;
  67.                     if (codeLength == geohashCode.Length)
  68.                     {
  69.                         var decryptedCode = new StringBuilder();//or var decryptedCode ="";
  70.                         foreach (var item in geohashCode)
  71.                         {
  72.                             decryptedCode.Append((char)(item + codeLength));//or var decryptedCode += (char)(item + codeLength);
  73.                         }
  74.                         Console.WriteLine($"Coordinates found! {name} -> {decryptedCode}");
  75.                         break;
  76.                     }
  77.                     else
  78.                     {
  79.                         Console.WriteLine("Nothing found!");
  80.                     }
  81.                 }
  82.                 else
  83.                 {
  84.                     Console.WriteLine("Nothing found!");
  85.                 }
  86.             }
  87.  
  88.             //string pattern = @"([#$%*&])(?<name>[A-z]+)(\1)=(?<lenght>\d+)!!(?<code>.+)";//Other
  89.             //string input = Console.ReadLine();
  90.             //while (true)
  91.             //{
  92.             //    Regex order = new Regex(pattern);
  93.             //    if (order.IsMatch(input))
  94.             //    {
  95.             //        string name = order.Match(input).Groups["name"].Value;
  96.             //        int lenght = int.Parse(order.Match(input).Groups["lenght"].Value);
  97.             //        string code = order.Match(input).Groups["code"].Value;
  98.             //        if (lenght == code.Length)
  99.             //        {
  100.             //            StringBuilder codee = new StringBuilder();
  101.             //            for (int i = 0; i < code.Length; i++)
  102.             //            {
  103.             //                char symbol = (char)(code[i] + lenght);
  104.             //                codee.Append(symbol);
  105.             //            }
  106.             //            Console.WriteLine($"Coordinates found! {name} -> {codee}");
  107.             //            return;
  108.             //        }
  109.             //        else
  110.             //        {
  111.             //            Console.WriteLine("Nothing found!");
  112.             //        }
  113.             //    }
  114.             //    else
  115.             //    {
  116.             //        Console.WriteLine("Nothing found!");
  117.             //    }
  118.             //    input = Console.ReadLine();
  119.             //}
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment