SimeonTs

SUPyF2 P.-Mid-Exam/4 November 2018 - 03. Quests Journal

Oct 31st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. """
  2. Technology Fundamentals Mid Exam - 4 November 2018
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1316#2
  4.  
  5. SUPyF2 P.-Mid-Exam/4 November 2018 - 03. Quests Journal
  6.  
  7. As a young adventurer, you start new quest every day, until you retire.
  8. Input / Constraints
  9. You start your adventurer path, receiving a journal with some beginner quests, separated with ', ' (comma and space).
  10. After that, until receiving "Retire!" you will be receiving different commands.
  11. Commands:
  12. • "Start - {quest}" – Receiving this command, you should add the given quest in your journal.
  13. If the quest already exists, you should skip this line.
  14. • "Complete - {quest}" – You should remove the quest from your journal, if it exists.
  15. • "Side Quest - {quest}:{sideQuest}" – You should check if the quest exists, if so,
  16.    add the side quest after the quest. Note that you shouldn`t add the sideQuest if it already exists.
  17. • "Renew – {quest}" – If the given quest exists, you should change its position and put it last in your journal.
  18. Output
  19. After receiving "Retire!" print the quests in the journal, separated by ", " (comma and space).
  20.  
  21. Examples:
  22. Input                               Output:
  23. Hello World, For loop, If else      Hello World, If else, While loop
  24. Start - While loop
  25. Complete - For loop
  26. Retire!
  27.  
  28. Input:                              Output:
  29. Hello World, If else                If else, Switch, Hello World
  30. Complete - Homework
  31. Side Quest - If else:Switch
  32. Renew - Hello World
  33. Retire!
  34. """
  35. quests = input().split(", ")
  36.  
  37. while True:
  38.     command = input().split(" - ")
  39.     if command[0] == "Retire!":
  40.         print(", ".join(quests))
  41.         break
  42.     elif command[0] == "Start":
  43.         quest = command[1]
  44.         if quest not in quests:
  45.             quests.append(quest)
  46.     elif command[0] == "Complete":
  47.         quest = command[1]
  48.         if quest in quests:
  49.             quests.remove(quest)
  50.     elif command[0] == "Side Quest":
  51.         quest, side_quest = command[1].split(":")
  52.         if side_quest not in quests and quest in quests:
  53.             quests.insert((quests.index(quest) + 1), side_quest)
  54.     elif command[0] == "Renew":
  55.         quest = command[1]
  56.         if quest in quests:
  57.             quests.remove(quest)
  58.             quests.append(quest)
Add Comment
Please, Sign In to add comment