SimeonTs

SUPyF2 P.-Mid-Exam/10 March 2019/1 - 03. Last Stop

Oct 29th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.87 KB | None | 0 0
  1. """
  2. Technology Fundamentals Mid Exam - 10 March 2019 Group 1
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1494#2
  4.  
  5. SUPyF2 P.-Mid-Exam/10 March 2019/1 - 03. Last Stop
  6.  
  7. Problem:
  8. The group has reached Paris and went to visit "La Louvre".
  9. They accidently found a map behind "The Wedding at Canna" painting.
  10. It had some instructions, so they have decided to follow them and see where they will lead them.
  11. Your job is to help them.
  12. Create a program that follows instructions in order to fulfil a quest.
  13. First, you will receive a collection of numbers – each representing a painting number.
  14. After that, you are going to be receiving instructions, until the "END" command is given.
  15. -   Change {paintingNumber} {changedNumber} –
  16.    find the painting with the first number in the collection (if it exists)
  17.    and change its number with the second number – {changedNumber}.
  18. -   Hide {paintingNumber} – find the painting with this value and if it exists and hide it (remove it).
  19. -   Switch {paintingNumber} {paintingNumber2} –
  20.    find the given paintings in the collections if they exist and switch their places.
  21. -   Insert {place} {paintingNumber} – insert the painting (paintingNumber) on the next place after the given one,
  22.    if it exists.
  23. -   Reverse – you must reverse the order of the paintings.
  24. Once you complete the instructions, print the numbers of the paintings on a single line, split by a space.
  25. Input / Constraints
  26. • On the 1st line, you are going to receive the numbers of the paintings, split by a single space –
  27.    integer numbers in the range [1…1000]
  28. • On the next lines, you are going to receive commands, until you receive the "END" command
  29. Output
  30. • Print the message you have received after the conversion of all numbers on a single line
  31. Examples:
  32.  
  33. Input:
  34. 115 115 101 114 73 111 116 75
  35. Insert 5 114
  36. Switch 116 73
  37. Hide 75
  38. Reverse
  39. Change 73 70
  40. Insert 10 85
  41. END
  42.  
  43. Output:
  44. 70 114 111 116 114 101 115 115
  45.  
  46. Comments:
  47. The first command is "Insert". You have to insert painting number 114 at the next index after the 5th:
  48. 115 115 101 114 73 111 114 116 75
  49. The "Switch" will switch number 116 with 73 and the collection should look like this:
  50. 115 115 101 114 116  111 114 73  75
  51. After receiving the"Hide" command, you must remove 75.
  52. After that you receive "Reverse" and you have to reverse the whole collection.
  53. By receiving "Change" you have to exchange the value 73 with the value – 70.
  54. The nextInsert"command is invalid, because there is no 11th index in the collection.
  55.  
  56. Input:
  57. 77 120 115 101 101 97 78 88 112 111 108 101 111 110
  58. Insert 5 32
  59. Switch 97 78
  60. Hide 88
  61. Change 120 117
  62. END
  63.  
  64. Output:
  65. 77 117 115 101 101 78 32 97 112 111 108 101 111 110
  66. """
  67. paintings = [int(painting) for painting in input().split()]
  68.  
  69. while True:
  70.     command = input().split()
  71.     if command[0] == "END":
  72.         break
  73.  
  74.     elif command[0] == "Change":
  75.         painting_number, changed_number = int(command[1]), int(command[2])
  76.         if painting_number in paintings:
  77.             paintings[paintings.index(painting_number)] = changed_number
  78.  
  79.     elif command[0] == "Hide":
  80.         painting_number = int(command[1])
  81.         if painting_number in paintings:
  82.             paintings.remove(painting_number)
  83.  
  84.     elif command[0] == "Switch":
  85.         painting_1, painting_2 = int(command[1]), int(command[2])
  86.         if painting_1 in paintings and painting_2 in paintings:
  87.             index_1 = paintings.index(painting_1)
  88.             index_2 = paintings.index(painting_2)
  89.             paintings[index_1] = painting_2
  90.             paintings[index_2] = painting_1
  91.  
  92.     elif command[0] == "Insert":
  93.         place, painting_number = int(command[1]) + 1, int(command[2])
  94.         if 0 <= place < len(paintings):
  95.             paintings.insert(place, painting_number)
  96.  
  97.     elif command[0] == "Reverse":
  98.         paintings = paintings[::-1]
  99.  
  100. print(*paintings)
Add Comment
Please, Sign In to add comment