Skip to content

Instantly share code, notes, and snippets.

@rishi93
Last active March 24, 2016 15:23
Show Gist options
  • Save rishi93/2f8ccd1f8b7135348478 to your computer and use it in GitHub Desktop.
Save rishi93/2f8ccd1f8b7135348478 to your computer and use it in GitHub Desktop.
Add Reversed - ADDREV
#Approach 1
def reverse_string(string):
return string[::-1] #Slicing Begin to end in steps of -1
t = int(input())
for testcase in range(0,t):
a,b = input().split()
result = str( int(reverse_string(a)) + int(reverse_string(b)) )
print( int(reverse_string(result)) )
#End
#Approach 2
def reverse(num):
s = 0
while num > 0:
d = num%10
s = (s*10)+d
num = num // 10
return s
t = int(input())
for testcase in range(0,t):
a,b = input().split()
a,b = int(a),int(b)
result = reverse(a)+reverse(b)
print(reverse(result))
#End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment