Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- We have the following operations defined for two-digit numbers. There are two possible ways of merging them:
- Merging ab and cd produces bc
- 42 merged with 17 produces 21
- 17 merged with 42 produces 74
- Squashing ab and cd produces a(b+c)d - the middle digit is the sum of b and c
- 42 squashed with 17 produces 437
- 39 squashed with 57 produces 347 (9 + 5 = 14, we use only the 4)
- You have a sequence of N two-digit numbers. Your task is to merge and squash each pair of adjacent numbers.
- Input
- All input data is read from the standard input
- On the first line, you will receive an integer N
- On the next N lines you will receive N two-digit numbers
- Each number will be on a separate line
- Output
- The output data is printed on the standard output
- On the first output line print the merged numbers
- There should be N - 1 of them
- Separate them by spaces
- On the second output line print the squashed numbers
- There should be N - 1 of them
- Separate them by spaces
- Constraints
- 2 <= N <= 1000
- Numbers will consist of two non-zero digits
- The input data will always be correct and there is no need to check it explicitly
- '''
- def merge_nums(i: str, j: str):
- return i[1] + j[0]
- def squash_nums(i: str, j: str):
- return i[0] + str((int(i[1]) + int(j[0])) % 10) + j[1]
- merge_l = []
- squash_l = []
- n = int(input())
- all_nums = [input() for _ in range(n)]
- for k in range(n - 1):
- merge_l.append(merge_nums(all_nums[k], all_nums[k + 1]))
- squash_l.append(squash_nums(all_nums[k], all_nums[k + 1]))
- print(*merge_l, sep=' ')
- print(*squash_l, sep=' ')
- # import random
- #
- # res = [str(random.randrange(1, 9, 1)) + str(random.randrange(1, 9, 1)) for _ in range(1000)]
- # print(*res, sep="\n")
Advertisement
Add Comment
Please, Sign In to add comment