結果

問題 No.39 桁の数字を入れ替え
ユーザー ronpooronpoo
提出日時 2023-08-23 08:43:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 319 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 71,544 KB
最終ジャッジ日時 2023-08-23 08:43:43
合計ジャッジ時間 2,966 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,436 KB
testcase_01 AC 69 ms
71,324 KB
testcase_02 AC 71 ms
70,988 KB
testcase_03 AC 73 ms
71,380 KB
testcase_04 AC 70 ms
71,312 KB
testcase_05 AC 71 ms
71,284 KB
testcase_06 AC 70 ms
71,016 KB
testcase_07 AC 69 ms
71,220 KB
testcase_08 AC 73 ms
71,408 KB
testcase_09 AC 69 ms
71,236 KB
testcase_10 AC 70 ms
71,476 KB
testcase_11 AC 70 ms
71,328 KB
testcase_12 AC 71 ms
71,368 KB
testcase_13 AC 71 ms
71,216 KB
testcase_14 AC 70 ms
71,248 KB
testcase_15 AC 70 ms
71,544 KB
testcase_16 AC 71 ms
71,436 KB
testcase_17 AC 71 ms
71,084 KB
testcase_18 AC 69 ms
71,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

S = str(N)
L = len(S)
s = list(S)
a = [int(v) for v in S]
a.sort(reverse=True)
idx = 0
for i in range(L):
    if int(S[i]) != a[i]:
        idx = i
        break
for j in range(L-1, -1, -1):
    if a[idx] == int(S[j]):
        s[idx], s[j] = s[j], s[idx]
        break
ans = ''.join(s)
print(int(ans))
0