結果

問題 No.39 桁の数字を入れ替え
コンテスト
ユーザー obakyan
提出日時 2019-05-01 09:35:53
言語 Lua
(LuaJit 2.1.1774638290)
コンパイル:
luajit -b _filename_ a.out
実行:
luajit _filename_
結果
WA  
実行時間 -
コード長 420 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 133 ms
コンパイル使用メモリ 6,528 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-05 00:05:54
合計ジャッジ時間 1,095 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

local orig = io.read("*n")
local t = {}
while(0 < orig) do
  local a = orig % 10
  table.insert(t, a)
  orig = math.floor(orig / 10)
end
local maxdig = 1
for i = 2, #t do
  if(t[maxdig] < t[i]) then maxdig = i end
end
local reppos = maxdig
for i = #t, maxdig, -1 do
  if(t[i] < t[maxdig]) then reppos = i break end
end
t[reppos], t[maxdig] = t[maxdig], t[reppos]
for i = #t, 1, -1 do
  io.write(t[i])
end
io.write("\n")
0