Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Eg:
- 1232 ab+cd -> a:1, b:2, c:3, d:2 -> 12+32 -> 44
- Input
- 3413289830 a-bcdefghij
- 776 a+bc
- 12345 a+bcde
- 1232 ab+cd
- 90602 a+bcde
- Constraints:
- N is in range [100, 1000000000]
- Assume that only valid expressions are provided (no leading zeros)
- I/p : 1232 ab+cd
- '''
- import sys
- test_cases = open(sys.argv[1], 'r')
- for line in test_cases.read().splitlines():
- operation = '+' if '+' in line else '-'
- input = line.split()
- numbers = input[0]
- if int(numbers) > 100 and int(numbers) < 1000000000:
- expression = input[1]
- index = expression.index(operation)
- left=numbers[:index]
- right=numbers[index:]
- if operation == '+':
- print int(left)+int(right)
- else:
- print int(left)-int(right)
- test_cases.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement