Advertisement
SimeonTs

SUPyF Lists - Extra 02. Integer Insertion

Jun 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. """
  2. Lists
  3. Check your answer: https://judge.softuni.bg/Contests/Practice/Index/425#1
  4.  
  5. 02. Integer Insertion
  6.  
  7. Problem:
  8. You will receive a list of integers on the same line (separated by one space).
  9. On the next lines, you will start receiving a list of strings, until you receive the string “end”.
  10. Your task is to insert each string (converted to integer) at a specific index in the list.
  11. The index is determined by the first digit of the number.
  12. Example: 514 >>> first digit – 5 >>> insert 514 at the 5th index of the list.
  13. After you insert all the elements, print the list, separated by single spaces.
  14. The input will always be valid and you don’t need to explicitly check if you’re inserting an element into a valid index.
  15.  
  16. Examples:
  17. Input:                              Output:
  18. 1 2 3 4 5 6 7 8 9                   1 1982 2 2 2772 25 3 4 5 8534 6 716 7 8 9
  19. 25
  20. 716
  21. 2772
  22. 1982
  23. 8534
  24. 2
  25. end
  26.  
  27. Input:                              Output:
  28. 3 12 66 243 8766                    3 12 12 33 66 56 243 8766
  29. 12
  30. 33
  31. 56
  32. end
  33.  
  34. Input:                              Output:
  35. 9 9 9 9 9 9 9 9 9 9                 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
  36. 9
  37. 9
  38. 9
  39. 9
  40. 9
  41. end
  42. """
  43.  
  44. nums = [int(item) for item in input().split(" ")]
  45.  
  46. while True:
  47.     string = input()
  48.     if string == "end":
  49.         break
  50.     integer = int(string)
  51.     first_num = int(string[0])
  52.     nums.insert(first_num, integer)
  53.  
  54. for num in nums:
  55.     print(num, end=" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement