Wednesday, October 4, 2017

Print Largest Even Number - Digits

Given a number N as the input, print the largest even number E that can be formed using the digits present in the number. (There will be at least one even digit).

Input Format:
The first line contains N.

Output Format:
The first line contains E.

Example Input/Output 1:
Input:
1902
Output:
9210

Solution:
n=list(input())
e=min(filter(lambda x:(ord(x)-ord('0'))%2==0,n))
n.remove(e)
n.sort(reverse=True)
n.append(e)
print(''.join(n))
Share: