Loading...

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

gina78 avatar gina78 4 Точки

Secret Chat

Здравейте, можели малко помощ не мога да си намеря грешката 87/100 ми дава

кода ми https://pastebin.com/xVyaYLaK

 

Secret Chat

You have plenty of free time, so you decide to write a program that conceals and reveals your received messages. Go ahead and type it in!

On the first line of the input you will receive the concealed message. After that, until the "Reveal" command is given, you will be receiving strings with instructions for different operations that need to be performed upon the concealed message in order to interpret it and reveal its true content. There are several types of instructions, split by ":|:"

  • InsertSpace:|:{index}
    • Inserts a single empty space at the given index. The given index will always be valid.
  • Reverse:|:{substring}
    • If the message contains the given substring, cut it out, reverse it and add it at the end of the message.
    • If not, print "error".
    • This operation should replace only the first occurrence of the given substring if there are more than one such occurrences.
  • ChangeAll:|:{substring}:|:{replacement}
    • Changes all occurrences of the given substring with the replacement text.

Input / Constraints

  • On the first line, you will receive a string with message.
  • On the next lines, you will be receiving commands, split by ":|:".

Output

  • After each set of instructions, print the resulting string.
  • After the "Reveal" command is received, print this message:
    "You have a new text message: {message}"

Examples

Input

Output

heVVodar!gniV

ChangeAll:|:V:|:l

Reverse:|:!gnil

InsertSpace:|:5

Reveal

hellodar!gnil

hellodarling!

hello darling!

You have a new text message: hello darling!

Comments

ChangeAll:|:V:|:l
heVVodar!gniV -> hellodar!gnil (We replace all occurrences of "V" with "l")

Reverse:|:!gnil

hellodar!gnil -> !gnil -> ling! -> hellodarling! (We reverse !gnil to ling! And put it in the end of the string)

InsertSpace:|:5

hellodarling! -> hello.darling! (We insert a space at index 5)

Finally, after receiving the "Reveal" command, we print the resulting message.

                                            Input                

Output

Hiware?uiy

ChangeAll:|:i:|:o

Reverse:|:?uoy

Reverse:|:jd

InsertSpace:|:3

InsertSpace:|:7

Reveal

Howare?uoy

Howareyou?

error

How areyou?

How are you?

You have a new text message: How are you?

 

 

Тагове:
0
PHP Fundamentals 22/04/2020 13:13:11
willystyle avatar willystyle 2472 Точки

има едно парче от стринга $е съм ти го кръстил, което забравяш да си долепиш.

case "Reverse":
            $substring = $command[1];
            $pos = strpos($str, $substring);
            if ($pos !== false) {
                $f = substr($str, 0, $pos);
                $l =  substr($str,  $pos, strlen($substring));
                $l = strrev($l);
                $e = substr($str, $pos + strlen($substring));
                $str = $f . $e . $l;
                echo "$str\n";
            } else {
                echo "error\n";
            }
            break;

 

0
gina78 avatar gina78 4 Точки

Много ти благодаря счупих се да мисля:)

1
willystyle avatar willystyle 2472 Точки

често чуждото око вижда по-лесно нашите малки грешки :)

0
gina78 avatar gina78 4 Точки

🙆

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