SimeonTs

SUPyF2 P.-Mid-Exam/30 June 2019/2. - Froggy Squad

Oct 28th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | None | 0 0
  1. """
  2. Programming Fundamentals Mid Exam - 30 June 2019 Group 2
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1683#2
  4.  
  5. SUPyF2 P.-Mid-Exam/30 June 2019/2. - Froggy Squad
  6.  
  7. Problem:
  8. Create a program that helps you keep track of the frogs that are on the riverside.
  9. Because you are an extreme animal lover, you also name them.
  10. You will receive the names of the frogs that are already on the riverside on a single line,
  11. separated by a single space in the following format:
  12. "{frog1} {frog2} {frog3}… {frogn}"
  13. Then you will receive commands that describe their action. There are five possible commands:
  14. • "Join {name}":
  15. o   A frog comes on the riverside and you need to add it in the end of your collection. Frog names will never repeat.
  16. • "Jump {name} {index}"
  17. o   A frog jumps out of the water and joins the other frogs.
  18. You need to add it in your collection on the given index, if the index exists.
  19. • "Dive {index}":
  20. o   The frog on the given index has decided to jump into the water.
  21. You have to remove it from your collection, if the index exists.
  22. • "First/Last {count}":
  23. o   Print the first/last {count} frogs separated by a single space.
  24. If the count requested is more than the frogs- just print them to the end.
  25. "{frog} {frog} {frog}"
  26. • "Print Normal/Reversed"
  27. o   Print the names of the frogs in your collection in normal
  28.    (in the order they have been added) or reversed order in the format described below, then stop the program:
  29. "Frogs: {frog1} {frog2}… {frogn}"
  30. Input
  31. • On the 1st line, you will receive the starting list with the names of the frogs separated by a single space.
  32. • On the next lines, you will receive commands in the format described above.
  33. Output
  34. • Print the list after the manipulations upon the "Print" command in the format described above.
  35.  
  36. Examples:
  37. Input:
  38. Blake Muggy Kishko
  39. Join Kvachko
  40. Dive 0
  41. First 10
  42. Print Reversed
  43.  
  44. Output:
  45. Muggy Kishko Kvachko
  46. Frogs: Kvachko Kishko Muggy
  47.  
  48. Comments:
  49. First, we receive the "Join Kvachko" command, so we add the frog in the end of the collection.
  50. Then, we receive the command "Dive  0", so we remove the frog on index 0.
  51. Also, we receive the command "First 10", which is more than the frogs we have, so we print all frogs instead.
  52. Lastly, we have to print the collection in reversed, so our output is: "Frogs: Kvachko Kishko Muggy".
  53.  
  54. Input:
  55. A B C D E F
  56. Join G
  57. Jump Q 3
  58. Last 3
  59. Dive 2
  60. Print Normal
  61.  
  62. Output:
  63. E F G
  64. Frogs: A B Q D E F G
  65. """
  66. frogs = input().split()
  67.  
  68. while True:
  69.     command = input().split()
  70.     if command[0] == "Join":
  71.         frogs.append(command[1])
  72.     elif command[0] == "Jump":
  73.         name, index = command[1], int(command[2])
  74.         if 0 <= index < len(frogs):
  75.             frogs.insert(index, name)
  76.     elif command[0] == "Dive":
  77.         index = int(command[1])
  78.         if 0 <= index < len(frogs):
  79.             frogs.pop(index)
  80.     elif command[0] == "First" or command[0] == "Last":
  81.         count = min(int(command[1]), len(frogs))
  82.         if command[0] == "First":
  83.             print(' '.join(frogs[:count]))
  84.         elif command[0] == "Last":
  85.             print(' '.join(frogs[-count:]))
  86.     elif command[0] == "Print":
  87.         if command[1] == "Normal":
  88.             print(f"Frogs: {' '.join(frogs)}")
  89.         elif command[1] == "Reversed":
  90.             print(f"Frogs: {' '.join(frogs[::-1])}")
  91.         break
Add Comment
Please, Sign In to add comment