No.39 Swapping Digits
タグ : / 解いたユーザー数 542
作問者 :
nmnmnmnmnmnmnm
Problem Statement
You are given a number N with at least 2 and at most 9 digits.
The number N does not contain the digit 0 in any position.
Every digit is one of the digits from 1 to 9.
You may freely choose two digits
and swap them, only once.
You may also choose not to swap.
When trying to make the largest possible number,
what is that largest number?
Input
N
N is a number with at least 2 and at most 9 digits.
Each digit is one of the digits from 1 to 9.
The digit 0 does not appear in any position.
Output
Output the largest number.
Do not forget the newline.
Sample
Sample 1
Input
12
Output
21
Swapping the 1 and the 2 of 12 makes 21.
Sample 2
Input
21
Output
21
You may also choose not to swap.
Sample 3
Input
1122
Output
2121
Swapping the first 1 and the last 2
gives 2121, which is the largest number.
Only one swap is allowed.
Sample 4
Input
999999999
Output
999999999
No matter what you do, the result is always 999999999.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。