SimeonTs

SUPyF2 P.-Mid-Exam/18 December 2018 - 02. Santa's List

Oct 30th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. """
  2. Technology Fundamentals Retake Mid Exam - 18 December 2018
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1395#1
  4.  
  5. SUPyF2 P.-Mid-Exam/18 December 2018 - 02. Santa's List
  6.  
  7. Problem:
  8. Its Christmas time and Santa needs your help with creating the list of noisy kids.
  9. Input
  10. You will receive the initial list with noisy kids each of them separated with "&".
  11. After that you will receive 4 types of commands until you receive "Finished!"
  12. • Bad {kidName} - adds a kid at the start of the list.  If the kid already exists skip this line.
  13. • Good {kidName} - removes the kid with the given name only if he exists in the list, otherwise skip this line.
  14. • Rename {oldName} {newName} – if the kid with the given old name exists change his name with the newer one.
  15. If he doesn't exist skip this line.
  16. • Rearrange {kidName} - If the kid exists in the list remove him from his current position and
  17.    add him at the end of the list.
  18. Constraints
  19. • You won't receive duplicate names in the initial list
  20. Output
  21. Print the list of all noisy kids joined by ", ".
  22. • "{firstKid}, {secondKid}, …{nthKid}"
  23.  
  24. Examples:
  25.  
  26. Input:                  Output:
  27. Peter&George&Mike       Joshua, George, Mike
  28. Bad Joshua
  29. Good Peter
  30. Finished!
  31.  
  32. Input:                                  Output:
  33. Joshua&Aaron&Walt&Dustin&William        Joshua, Paul, Dustin, William, Jon
  34. Good Walt
  35. Bad Jon
  36. Rename Aaron Paul
  37. Rearrange Jon
  38. Rename Peter George
  39. Finished!
  40. """
  41. noisy_kids = input().split("&")
  42.  
  43. while True:
  44.     command = input().split()
  45.     if command[0] == "Finished!":
  46.         print(", ".join(noisy_kids))
  47.         break
  48.  
  49.     elif command[0] == "Bad":
  50.         bad_name = command[1]
  51.         if bad_name not in noisy_kids:
  52.             noisy_kids.insert(0, bad_name)
  53.  
  54.     elif command[0] == "Good":
  55.         good_kid = command[1]
  56.         if good_kid in noisy_kids:
  57.             noisy_kids.remove(good_kid)
  58.  
  59.     elif command[0] == "Rename":
  60.         old_name, new_name = command[1], command[2]
  61.         if old_name in noisy_kids:
  62.             index_old_name = noisy_kids.index(old_name)
  63.             noisy_kids[index_old_name] = new_name
  64.  
  65.     elif command[0] == "Rearrange":
  66.         kid_name = command[1]
  67.         if kid_name in noisy_kids:
  68.             noisy_kids.remove(kid_name)
  69.             noisy_kids.append(kid_name)
Add Comment
Please, Sign In to add comment