t = int(input())
while(t):
arr = [int(x) for x in input().split()]
A = arr[0]
B = arr[1]
a = A // 10
b = A % 10
c = B // 10
d = B % 10
if(A < 10 and B < 10):
print(A + B)
elif(A < 10 and B >= 10):
print(max(c+b*10+d, d+c*10+b, b+c*10+d))
elif(B < 10 and A >= 10):
print(max(a+b*10+d, d+b*10+a, a+d*10+b))
else:
print(max(d*10+b+c*10+a, c*10+b+a*10+d, a*10+c+b*10+d, a*10+d+c*10+b))
t -= 1
your code is giving wrong output for this test case :-
1
19 7
your output:- 98
correct output :- 80
you cannot swap digits of same number , you can’t swap 1 with 9 , you can swap 7 with either 9 or 1 in order to get max value.
@pkpawan123 thank you for the test case,but the problem was in 2nd elif where i was multiplying by 10 the ones digit,whichshould have been the test digit. Thanks for the reply man it is resolved.
nice you did it yourself .
your program is failing for these test cases
: -
1
7 9
your output -97
expected output -16
this is because you are checking the condition of (a<10 and b<10) at the end , you should check this condition before checking (b<10) .
2nd test case that is failing is
1
69 67
your output -145
expected output-163
as we can do atmost 1 swap we will swap 9 with 6 so now numbers are 66 and 97 so output is 163.
thanks for the help bro!!
bro your code is providing correct output to all my cases , i was not able to find test case that fail . i would recommend you to check out the editorial of this question.
No problem ,thanks for the reply.