Loading...

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

evgeni4 avatar evgeni4 12 Точки

Message Decrypter

Здравейте колеги, може ли малко помощ. за тая задача

проверката ми дава 80/100 

това ми е кода https://pastebin.com/we2ZcgM7

Message Decrypter

Create a program, that checks if inputs have a valid message and decrypt it. On the first line you will receive a number that indicates how many inputs you will receive on the next lines.

A message is valid when:

  • There is nothing else before and after it
  • It starts with a tag, which is surrounded by either '$' or '%' (but not both at the same time), the tag itself has to be minimum 3 characters long, start with a uppercase letter, followed only by lowercase letters
  • There is a colon and a single white space after the tag
  • There are 3 groups consisting of numbers between '[' and ']', followed by a pipe ('|')

Example for a valid message:

"$Request$: [73]|[115]|[32]|"

You must check if the message is valid and if it is- decrypt it, if it isn’t - print the following message:

"Valid message not found!"

Decrypting a message means to take all numbers and turn them into ASCII symbols. After successful decrypt, print it in the following format:

{tag}: {decryptedMessage}

Input

  • On the first line - n - the count of inputs.
  • On the next n lines - input that you have to check if it has a valid message.

Output

  • Print all results from each input, each on a new line.

Examples

Input

Output

Comment

4

$Request$: [73]|[115]|[105]|

%Taggy$: [73]|[73]|[73]|

%Taggy%: [118]|[97]|[108]|

$Request$: [73]|[115]|[105]|[32]|[75]|

 

Request: Isi

Valid message not found!

Taggy: val

Valid message not found!

We have 3 input lines to check.
The first one follows the rules and is valid. The second one doesn’t because the tag is surrounded by both '%' and '$'. The third one has a valid message and is in the beginning of the input. The last one is invalid because it has more than 3 groups of numbers.

3

This shouldnt be valid%Taggy%: [118]|[97]|[108]|

$tAGged$: [97][97][97]|

$Request$: [73]|[115]|[105]|true

Valid message not found!

Valid message not found!

Valid message not found!

 

 

Тагове:
0
PHP Fundamentals
willystyle avatar willystyle 2472 Точки
<?php
$n = intval(readline());
$regex= '/^([$%])([A-Z][a-z]{2,})\1: \[(\d+)\]\|\[(\d+)\]\|\[(\d+)\]\|$/';
for ($d = 0; $d < $n; $d++) {
    $message = readline();
    if (preg_match($regex, $message, $matches)) {        
        $tag = $matches[2];
        $decryptedMessage = chr($matches[3]) . chr($matches[4]) . chr($matches[5]);
        echo "{$tag}: {$decryptedMessage}\n";
    } else {
        echo "Valid message not found!\n";
    }
}

 

0
evgeni4 avatar evgeni4 12 Точки

Благодаря ти много

1
Radothepro avatar Radothepro 1 Точки

Някой да има C# решение, не мога да я направя няпълно вярна, благодаря предварително.

 

0
svephoto avatar svephoto 1191 Точки

Можеш да пуснеш един линк с твоя код да го видим.

0
Radothepro avatar Radothepro 1 Точки

Ако имах, щях върпоса е, че нямам никаква идея как да стане

0
svephoto avatar svephoto 1191 Точки

Кое, да споделиш код ли? Ако е това, можеш да ползваш pastebin.com за целта.

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