Професионална програма
Loading...
V3lin avatar V3lin 1 Точки

The Imitation Game

Здравейте, 

Опитвам се да реша следната задача: 

 

During World War 2, you are a mathematician who has joined the cryptography team to decipher the enemy's enigma code. Your job is to create a program to crack the codes.

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

  1. "Move {number of letters}":
    • Moves the first n letters to the back of the string
  2. "Insert {index} {value}":
    • Inserts the given value before the given index in the string
  3. "ChangeAll {substring} {replacement}":
    • Changes all occurrences of the given substring with the replacement text

Input / Constraints

  1. On the first line, you will receive a string with a message.
  2. On the following lines, you will be receiving commands, split by '|' .

Output

  1. After the "Decode" command is received, print this message:
    "The decrypted message is: {message}"

Examples

Input

Output

zzHe

ChangeAll|z|l

Insert|2|o

Move|3

Decode

The decrypted message is: Hello

Comments

ChangeAll|z|l

zzHe → llHe (We replace all occurrences of 'z' with 'l')

Insert|2|o

llHe → lloHe (We add an 'o' before the character on index 2)

Move|3

lloHe → Hello (We take the first three characters and move them to the end of the string)

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

Input

Output

owyouh

Move|2

Move|3

Insert|3|are

Insert|9|?

Decode

The decrypted message is: howareyou?

Ето и кода ми: https://pastebin.com/nWNd7fvM

Judge ми връща 33/100, а изхода зададен в задачата го връща правилно. Не мога да открия къде греша. Моля за съвет.

 Благодаря предварително.

Тагове:
0
Python Fundamentals
icowwww avatar icowwww 1823 Точки

Здравей,

Пренаписах метода ChangeAll, защото хвърля грешки и явно просто е нагласено да мине нулевия тест с това двойно изтриване на елемент. 

В Insert трябва да добавиш новия стринг не в един елемент, а както го ползваш- масив от символи:

https://pastebin.com/czKdHx6a

0
31/10/2021 00:25:47
V3lin avatar V3lin 1 Точки

Много благодаря за помощта.

0