Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem 1. The Isle of Man TT Race
- 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.
- Write a program that decrypts messages. You’re going to receive a few notes that contain the following information:
- • Name of racer
- 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.
- • Length of geohashcode
- o Begins after the "=" sign and it is consisted only of numbers.
- • Encrypted geohash code
- o Begins after these symbols - “!!”. It may contain anything and the message always ends with it.
- Examples for valid input:
- #SteveHislop#=16!!tv5dekdz8x11ddkc
- Examples of invalid input:
- %GiacomoAgostini$=7!!tv58ycb – The length is the same, but the name is not surrounded by matching signs.
- $GeoffDuke$=6!!tuvz26n35dhe4w4 – The length doesn't match the lengh of the code.
- &JoeyDunlop&!!tvndjef67t=14 – The length should be before the code.
- 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:
- "Coordinates found! {nameOfRacer} -> {geohashcode}"
- and stop the program. Otherwise, after every invalid message print:
- "Nothing found!"
- Input / Constraints
- • You will be receiving strings.
- • There will always be a valid message.
- Output
- • If you find the right coordinates, print: "Coordinates found! {nameOfRacer} -> {geohashcode}".
- • Otherwise, print: "Nothing found!".
- Examples
- Input Output
- %GiacomoAgostini%=7!!hbqw Nothing found!
- &GeoffDuke*=6!!vjh]zi Nothing found!
- JoeyDunlop=10!!lkd,rwazdr Nothing found!
- Mike??Hailwood=5!![pliu Coordinates found! SteveHislop -> tv5dekdz8x11ddkc
- #SteveHislop#=16!!df%TU[Tj(h!!TT[S Nothing found!
- Comments
- The first line matches, but the length of the code doesn't match the given number, so we print "Nothing found!"
- The second line begins with "&", but ends with "*", so we print "Nothing found!"
- The third line is not valid because the name is not surrounded with one of the allowed symbols.
- The forth line is not a match, because the name doesn't contain only letters.
- 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.
- Ian6Hutchinson=7!!\(58ycb4 Nothing found!
- #MikeHailwood#!!'gfzxgu6768=11 Nothing found!
- slop%16!!plkdek/.8x11ddkc Nothing found!
- $Steve$=9Hhffjh Nothing found!
- *DavMolyneux*=15!!efgk#'_$&UYV%h% Coordinates found! DaveMolyneux -> tuvz26n35dhe4w4
- RichardQ^uayle=16!!fr5de5kd Nothing found!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace Final_Exam___14_April_2019_Group_II
- {
- class Program
- {
- static void Main(string[] args)
- {
- while (true)//My
- {
- var messages = Console.ReadLine();
- var pattern = @"^(#|\$|%|\*|&)(?<Name>[A-z]+)\1=(?<LengthCode>\d+)!!(?<Geohashcode>.+)$";
- var matchPattern = Regex.Match(messages, pattern);
- if (matchPattern.Success)
- {
- var name = matchPattern.Groups["Name"].Value;
- var codeLength = int.Parse(matchPattern.Groups["LengthCode"].Value);
- var geohashCode = matchPattern.Groups["Geohashcode"].Value;
- if (codeLength == geohashCode.Length)
- {
- var decryptedCode = new StringBuilder();//or var decryptedCode ="";
- foreach (var item in geohashCode)
- {
- decryptedCode.Append((char)(item + codeLength));//or var decryptedCode += (char)(item + codeLength);
- }
- Console.WriteLine($"Coordinates found! {name} -> {decryptedCode}");
- break;
- }
- else
- {
- Console.WriteLine("Nothing found!");
- }
- }
- else
- {
- Console.WriteLine("Nothing found!");
- }
- }
- //string pattern = @"([#$%*&])(?<name>[A-z]+)(\1)=(?<lenght>\d+)!!(?<code>.+)";//Other
- //string input = Console.ReadLine();
- //while (true)
- //{
- // Regex order = new Regex(pattern);
- // if (order.IsMatch(input))
- // {
- // string name = order.Match(input).Groups["name"].Value;
- // int lenght = int.Parse(order.Match(input).Groups["lenght"].Value);
- // string code = order.Match(input).Groups["code"].Value;
- // if (lenght == code.Length)
- // {
- // StringBuilder codee = new StringBuilder();
- // for (int i = 0; i < code.Length; i++)
- // {
- // char symbol = (char)(code[i] + lenght);
- // codee.Append(symbol);
- // }
- // Console.WriteLine($"Coordinates found! {name} -> {codee}");
- // return;
- // }
- // else
- // {
- // Console.WriteLine("Nothing found!");
- // }
- // }
- // else
- // {
- // Console.WriteLine("Nothing found!");
- // }
- // input = Console.ReadLine();
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment