Last active
March 24, 2016 15:23
-
-
Save rishi93/2f8ccd1f8b7135348478 to your computer and use it in GitHub Desktop.
Add Reversed - ADDREV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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