Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

poli1993 avatar poli1993 11 Точки

JS Fundamentals - Exam Preparation - The Isle of Man TT Race

Здравейте, 

Задачата ми минава в Judge 85/100  и не мога да намеря проблема. Бих се радвала, ако някой може да ми помогне. Предварително благодаря :) 

Това е кода ми: https://pastebin.com/sqgKKrFX

Условие: 

Write a program that decrypts messages. You’re going to receive a few notes that contain the following information:

  • Name of racer
    • 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
    • Begins after the "=" sign and it is consisted only of numbers.
  • Encrypted geohash code
    • 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

&GeoffDuke*=6!!vjh]zi

JoeyDunlop=10!!lkd,rwazdr

Mike??Hailwood=5!![pliu

#SteveHislop#=16!!df%TU[Tj(h!!TT[S

Nothing found!

Nothing found!

Nothing found!

Nothing found!

Coordinates found! SteveHislop -> tv5dekdz8x11ddkc

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

#MikeHailwood#!!'gfzxgu6768=11

slop%16!!plkdek/.8x11ddkc

$Steve$=9Hhffjh

*DavMolyneux*=15!!efgk#'_$&UYV%h%

RichardQ^uayle=16!!fr5de5kd

Nothing found!

Nothing found!

Nothing found!

Coordinates found! DaveMolyneux -> tuvz26n35dhe4w4

 

Тагове:
0
JavaScript Fundamentals
willystyle avatar willystyle 2472 Точки
let pattern = /(#|\$|%|\*|&)(?<name>[A-Za-z]+)\1=(?<length>\d+)!!(?<code>.+)/;

 

0
EvgeniJD avatar EvgeniJD 35 Точки

А има ли възможност regExp-а да стане по някакъв подобен начин:

([#$%*&])([A-Za-z]+)\1=(\d+)!!.{\3}

Понеже в задачата се изисква броя на символите след !! да са точно колкото цифрата преди тях. Пробвах с референция към групата, в случая 3-та, но не стана.

0
willystyle avatar willystyle 2472 Точки

Иска ти се /([#$%*&])([A-z]+)\1=(\d+)!!(.{\q3})$/
да работи, за съжаление не. Regex енжина на C# има balancing groups и е по-лесно, но в PCRE няма и се ползват други хватки, които твърде много усложняват. Може да прочетеш статии на темата "Capturing Quantifiers and Quantifier Arithmetic". Но в случая за да спестиш една проверка с if, ще си усложниш регекса много и ще стане абсолютно нечетим.

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.