Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Arriving_at_Katmandu
- {
- class Program
- {
- static void Main()
- {
- //solved with a little regex and many if-s
- while (true)
- {
- string enterInfo = Console.ReadLine();
- if (enterInfo == "Last note")
- {
- break;
- }
- else
- {
- bool isCorrect = true;
- //enter the data for the peaks, split to get the mountain
- string[] data = enterInfo.Split("=").ToArray();
- //should be of two parts - mountain and the rest of the data
- if (data.Length == 2)
- {
- //get the mountain name to check if it is correct
- string namePeak = data[0];
- //get pattern
- Regex RgxUrl = new Regex("^[a-zA-Z0-9!@#$?]+$");
- //check if the string matches the pattern, returns true/false
- bool isPeak = RgxUrl.IsMatch(namePeak);
- if (isPeak == true)
- {
- //we have it
- string mountain = GetName(namePeak);
- //split to get the length and the name of the hashcode
- string[] lengthNameHash = data[1].Split("<<").ToArray();
- //should be of length 2
- if (lengthNameHash.Length == 2)
- {
- //the first element must be an integer
- int length;
- //check if it is integer
- bool isNum = int.TryParse(lengthNameHash[0], out length);
- if (isNum)
- {
- //get the hashcode name
- string geohash = lengthNameHash[1];
- //check if the name is with the stated length
- if (geohash.Length == length)
- Console.WriteLine($"Coordinates found! {mountain} -> {geohash}");
- else
- isCorrect = false;
- }
- else
- isCorrect = false;
- }
- }
- else
- isCorrect = false;
- }
- else
- isCorrect = false;
- if (isCorrect == false)
- {
- Console.WriteLine("Nothing found!");
- }
- }
- }
- }
- static string GetName(string name)
- {
- string newName = "";
- for (int i = 0; i < name.Length; i++)
- {
- if (name[i] >= 'A' && name[i] <= 'Z'
- || name[i] >= 'a' && name[i] <= 'z'
- || name[i] >= '0' && name[i] <= '9')
- {
- newName += name[i];
- }
- }
- return newName;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement