Given a string of form x + a = b where a and b are integer, find value of x [Note that spaces may or may not be there, for example, input can either be x+a=b or x + a = b or x+a = b]. 
For example if input string is x + 12 = 3 then output should be -9
 
Example 1:
Input: str = "x+5=2"
Output: -3
Explanation: 2 - 5 = -3
Example 2:
Input: str = "x+10=20"
Output: 10
Explanation: 20 - 10 = 10
 
Your Task:
You don't need to read or print anything. Your task is to complete the function solve() which takes the string str as input parameter and returns the value of the x.
 
Expected Time Complexity: O(1)
Expected Space Complexity: O(1) 
 
Constraints:
1 <= a, b <= 1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

	def Evaluate(self, str):

		# Code here

Solutions:
class Solution:

	def Evaluate(self, str):
		x = str.split('=')
		b = int(x[1])
		y = x[0].split('+')
		a = int(y[1])
		return b - a


import re

class Solution:

	def Evaluate(self, str):
		m = str.split('=')
		q = re.split('[+-]', m[0])
		return int(m[-1]) - int(q[-1])


class Solution:

	def Evaluate(self, str):
		a = ''
		for i in range(len(str)):
			if str[i] == '+':
				p = i
			elif str[i] == '=':
				q = i
		a = int(str[p + 1:q])
		b = int(str[q + 1:])
		return int(b - a)


class Solution:

	def Evaluate(self, st):
		st = st.replace(' ', '')
		(a, b) = st.split('+')[1].split('=')
		return int(b) - int(a)


class Solution:

	def Evaluate(self, str):
		a = str.index('=')
		b = str.index('+')
		x = str[a + 1:]
		y = str[b + 1:a]
		return int(x) - int(y)


class Solution:

	def Evaluate(self, str):
		s = str.split('+')
		a = s[1]
		b = a.split('=')
		return int(b[1]) - int(b[0])


class Solution:

	def Evaluate(self, str):
		eqn = str.split('+')[1].split('=')
		return int(eqn[1]) - int(eqn[0])


class Solution:

	def Evaluate(self, st):
		st = st.replace('+', ' ')
		st = st.replace('=', ' ')
		s = st.split(' ')
		ans = []
		for i in s:
			if i.isnumeric():
				ans.append(i)
		return int(ans[1]) - int(ans[0])


class Solution:

	def Evaluate(self, s):
		g = ''
		for i in s:
			if i.isdigit():
				g += i
			else:
				g += ' '
		res = [int(i) for i in g.split(' ') if i.isdigit()]
		return res[1] - res[0]
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		str = input()
		ob = Solution()
		ans = ob.Evaluate(str)
		print(ans)


class Solution:

	def Evaluate(self, str):
		str = str.replace(' ', '')
		str = str.replace('x+', '')
		l = str.split('=')
		return int(l[1]) - int(l[0])
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		str = input()
		ob = Solution()
		ans = ob.Evaluate(str)
		print(ans)


class Solution:

	def Evaluate(self, str):
		j = str.index('+')
		k = str.index('=')
		m = ''
		n = ''
		for i in range(j + 1, k):
			m += str[i]
		for i in range(k + 1, len(str)):
			n += str[i]
		c = 0
		if '+' in str:
			return int(n) - int(m)
		else:
			return int(n) + int(m)