Zeltops 0 Точки

## 01. Arriving in Kathmandu - Technology Fundamentals Final Exam - 14 April 2019 Group I

Judge ми дава 80/100, ако някой може да ми даде правилно решение или да ми помогне с моето ще му бъда много благодарен.

Ето моето решение: https://pastebin.com/pf5x04z0

Условието: https://judge.softuni.bg/Contests/1516/Technology-Fundamentals-Final-Exam-14-April-2019-Group-I

или:

Write a program that decrypts messages, which contain information about coordinates. You are looking for names of peaks in the Himalayas and their geohash coordinates. Keep reading lines until you receive the "Last note" message.

• Name of the peak
• It is consisted of letters (upper and lower), numbers and some of the following characters between its letters – "!" "@" "#" "\$" "?". Example for valid names: “!@K?#2!#” (K2).
• The length of the geohashcode
• Begins after the "=" (equals) sign and is consisted only of numbers.
• The geohash code
• Begins after these symbols – "<<", may contain anything and the message always ends with it.

Examples for valid input:

"!Ma\$\$ka!lu!@=9<<ghtucjdhs" – all the components are there – name of the peek, length of the geohashcode and a geohashcode.

"!@Eve?#rest!#=7<<vbnfhfg"

Examples of invalid input:

"anna@fg<<jhsd@bx!=4" – their order is wrong. The name should be first, the length after and the code last.

"#n...s!n-<<tyuhgf4" – the length is missing and the name contains dots.

"Nan\$ga!Parbat=8<<gh2tn – the length of the geohash code doesn't match the given number.

The geohash code you are looking for is with length exactly as much as the given length in the message and the information must be in the exact given order, otherwise it is considered invalid. If you find it, print the following message:

"Coordinates found! {nameOfMountain} -> {geohashcode}"

Otherwise print: “Nothing found!” after every invalid message.

## Input / Constraints

• You will be receiving strings until you get the “Last note” message.

## Output

• If you find the right coordinates, print: "Coordinates found! {nameOfMountain} -> {geohashcode}".
• If the message is invalid, print: "Nothing found!".

## Examples

 Input Output !@Ma?na?sl!u@=7< tv5dekdz8x11ddkc Comments The first line is invalid, because the length – 7, doesn't match the length of the code. The second line is invalid, because the length should be consisted only of numbers. The third line is invalid, because the name contains symbols that are not allowed – ".", ",". The forth line is invalid, because the "=" sign before the length is missing. The fifth line is valid, so we print the appropriate message. Ka?!#nch@@en@ju##nga@=3< twm03q2rx5hpmyr6 Nothing found!
Тагове:
0
krum_43 311 Точки

Защо сплитваш стринга към списък?Тук и масив би ти свършил работа,

:)

0
Milko123 1 Точки

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;

namespace _01._Arriving_in_Kathmandu
{
class Program
{
static void Main(string[] args)
{
string pattern = @"([A-Za-z0-9!@?#\$]+)=(\d+)<<(.*)\$";
Regex regex = new Regex(pattern);

while (command!="Last note")
{
Match match = regex.Match(command);
if (match.Success)
{
string name = match.Groups[1].Value;
int length = int.Parse(match.Groups[2].Value);
string geodashCode = match.Groups[3].Value;

if (geodashCode.Length==length)
{
name = name.Trim(new char[] { '!','@', '?', '#', '\$' });
Console.WriteLine(\$"Coordinates found! {name} -> {geodashCode}");
}
else
{
Console.WriteLine("Nothing found!");
}
}
else
{
Console.WriteLine("Nothing found!");
}

}

}
}
}

Някой знае ли защо "Trim" метода ми не действа за символ "@"? И как трябва да я вмъкна за да работи?

0
vasil.vasileff 3 Точки

Първо си оправи regex-а:  ^([A-Za-z0-9!@?#\$]+)=(\d+)<<(.+)\$

В тази задача не е подходящо да използваш Trim метода. Trim () премахва всички определени символи от началото и края на стринга. Ако не посочиш нищо, ще премахне място. Ако нито един символ не може да бъде отрязан от текущия стринг, методът връща текущия стринг непроменен.

Ето защо при вход:  !###Anna@pur@na##  - nameOfMountain се получава:  Anna@pur@na

Има много варианти, които можеш да използваш вместо Trim. Например с for цикъл:

string nameOfMountain =  "";

for (int i = 0; i < name.Length; i++)
{
char currentCh = name[i];

if (char.IsLetterOrDigit(currentCh))
{
nameOfMountain += currentCh;
}
}

0
Milko123 1 Точки

Благодаря за отговора.

0
02/04/2020 21:17:39