Advertisement
stsp93

solve

Jul 24th, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. Problem 1 - The Imitation Game
  2. Problem for exam preparation for the Programming Fundamentals Course @SoftUni.
  3. Submit your solutions in the SoftUni judge system at https://judge.softuni.org/Contests/Practice/Index/2525#0.
  4.  
  5. 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.
  6. 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 '|'
  7. • "Move {number of letters}":
  8. o Moves the first n letters to the back of the string
  9. • "Insert {index} {value}":
  10. o Inserts the given value before the given index in the string
  11. • "ChangeAll {substring} {replacement}":
  12. o Changes all occurrences of the given substring with the replacement text
  13. Input / Constraints
  14. • On the first line, you will receive a string with a message.
  15. • On the following lines, you will be receiving commands, split by '|' .
  16. Output
  17. • After the "Decode" command is received, print this message:
  18. "The decrypted message is: {message}"
  19. Examples
  20. Input Output
  21. zzHe
  22. ChangeAll|z|l
  23. Insert|2|o
  24. Move|3
  25. Decode The decrypted message is: Hello
  26. Comments
  27. ChangeAll|z|l
  28. zzHe → llHe (We replace all occurrences of 'z' with 'l')
  29. Insert|2|o
  30. llHe → lloHe (We add an 'o' before the character on index 2)
  31. Move|3
  32. lloHe → Hello (We take the first three characters and move them to the end of the string)
  33. Finally, after receiving the "Decode" command, we print the resulting message.
  34. Input Output
  35. owyouh
  36. Move|2
  37. Move|3
  38. Insert|3|are
  39. Insert|9|?
  40. Decode The decrypted message is: howareyou?
  41. JS Examples
  42. Input Output
  43. [
  44. 'zzHe',
  45. 'ChangeAll|z|l',
  46. 'Insert|2|o',
  47. 'Move|3',
  48. 'Decode',
  49. ] The decrypted message is: Hello
  50. Comments
  51. ChangeAll|z|l
  52. zzHe → llHe (We replace all occurrences of 'z' with 'l')
  53. Insert|2|o
  54. llHe → lloHe (We add an 'o' before the character on index 2)
  55. Move|3
  56. lloHe → Hello (We take the first three characters and move them to the end of the string)
  57. Finally, after receiving the "Decode" command, we print the resulting message.
  58. Input Output
  59. [
  60. 'owyouh',
  61. 'Move|2',
  62. 'Move|3',
  63. 'Insert|3|are',
  64. 'Insert|9|?'
  65. 'Decode',
  66. ] The decrypted message is: howareyou?
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement