0
Largest Even Number
The program must accept two numbers N1 and N2 as the input and it must print the largest possible even number with non-zero unit digit as the output containing all the digits from both the numbers. If an even number with non-zero unit digit cannot be formed using the digits from the two numbers, the program must print -1 as the output. Note: The last digit must not be zero. Example Input/Output 1: Input: 784201 86976 Output: 98877664102
2 Réponses
+ 1
even='2468'
c=sorted(input()+input())
if all(i not in even for i in c):
print("-1")
else:
j=min(range(len(c)),key=lambda i:int(c[i] not in even))
c.insert(0,c[j])
del c[j+1]
print(''.join(c[::-1]))
https://code.sololearn.com/cDD2F6NdwvYX/?ref=app
0
1) append all numbers to a list.
2) sort numbers
3) iterate over the list until int(x) % 2 == 0
4) move the first number with their index and break
5) print output
since i seem to get dislikes with above, I fastcoded the thing
https://code.sololearn.com/cEZd8PdTNxYE/?ref=app