Loading...

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

Goganovradostin avatar Goganovradostin 1 Точки

zадача от Final Exam

Здравейте Колеги,

 

някой дали е направил такава тъпотия като мене :( и дали може да ми хелпне :

условието на задачата е : а решението https://pastebin.com/sxCQAjpm

Programming Fundamentals Final Exam 09.08.2020

Problem 1. World Tour

You are a world traveller and your next goal is to make a world tour. In order to do that, you have to plan out everything first. To start with, you would like to plan out all of your stops where you will have a break.

On the first line you will be given a string containing all of your stops. Until you receive the command "Travel", you will be given some commands to manipulate that initial string. The commands can be:

  • Add Stop:{index}:{string} – insert the given string at that index only if the index is valid
  • Remove Stop:{start_index}:{end_index} – remove the elements of the string from the starting index to the end index (inclusive) if both indices are valid
  • Switch:{old_string}:{new_string} – if the old string is in the initial string, replace it with the new one. (all occurrences)

Note: After each command print the current state of the string

After the "Travel" command, print the following: "Ready for world tour! Planned stops: {string}"

Input / Constraints

  • JavaScript: you will receive a list of strings

Output

  • Print the proper output messages in the proper cases as described in the problem description

Examples

Input

Output

Hawai::Cyprys-Greece

Add Stop:7:Rome

Remove Stop:11:23

Switch:Hawai:Bulgaria

Travel

Hawai::RomeCyprys-Greece

Hawai::Rome-Greece

Bulgaria::Rome-Greece

Ready for world tour! Planned stops: Bulgaria::Rome-Greece

 

 

Тагове:
0
Python Fundamentals
D.V.Ivanov avatar D.V.Ivanov 6 Точки

Ето моето решение (след няколко "хиляди":) опита) :

string = input()


command = input()

while not command == "Travel":
    new_command = command.split(":")
    if "Add Stop" in new_command:
        index = int(new_command[1])
        text = new_command[2]
        if index <= len(string) and index >= 0:
            part_1 = string[:index]
            part_2 = string[index:]
            string = part_1 + text + part_2
            print(f"{string}")
    elif "Remove Stop" in new_command:
        start = int(new_command[1])
        end = int(new_command[2])
        if start >= 0 and start <= end and end < len(string):
            part_1 = string[:start]
            part_2 = string[end + 1:]
            string = part_1 + part_2
        print(f"{string}")
    elif "Switch" in new_command:
        old = new_command[1]
        new = new_command[2]
        test = string.replace(old, new)
        string = test
        print(f"{string}")
    command = input()


print(f"Ready for world tour! Planned stops: {string}")
0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.