Loading...
Dimytar1107 avatar Dimytar1107 1 Точки

The Final Quest

The Final Quest

After walking through fire, the group has reached the final step of the quest. They have received a list with instructions that will help them resolve the last riddle that will lead them to the truth about the Hunting Games.

Create a program that follows given instructions. You will receive a collection of words on a single line, split by a single space. They are not what they are supposed to be, so you have to follow the instructions in order to find the real message. You will be receiving commands. Here are the possible ones:

  • Delete {index} – removes the word after the given index if it is valid.
  • Swap {word1} {word2} – find the given words in the collections if they exist and swap their places.
  • Put {word} {index} – add a word at the previous place {index} before the
    given one, if it is valid. Note: putting at the last index simply appends the word to the end of the list.
  • Sort – you must sort the words in descending order.
  • Replace {word1} {word2} – find the second word {word2} in the collection (if it exists) and replace it with the first word – {word1}.

Follow them until you receive the "Stop" command. After you have successfully followed the instructions, you must print the words on a single line, split by a space.

Input / Constraints

  • On the 1st line, you are going to receive the collection of words, split by a single space – strings
  • On the next lines, you are going to receive commands, until you receive the "Stop" command

Output

  • Print the words you have gathered on a single line, split by a single space

Examples

Input

Output

Congratulations! You last also through the have challenge!

Swap have last

Replace made have

Delete 2

Put it 4

Stop

Congratulations! You made it through the last challenge!

Comments

First, we receive the command “Swap”, so we change the positions of the words have and last. The text at this point should look like this:

Congratulations! You have also through the last challenge!

After that, we receive “Replace” and we have to replace the second word – “have” with the first – “made”. Afterwards we have to delete the word, which is after the second index. And finally, we have to put a word on the previous position before 4.

Input

Output

This the my quest! final

Put is 2

Swap final quest!

Delete 2

Stop

This is the final quest!

 

 

 

 

 

 

 

Здравейте. Judge ми дава 91/100. Ако може някой да помогне , ще съм благодарен.

https://pastebin.com/ErLv4Tne

 

 

 

 

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