結果

問題 No.39 桁の数字を入れ替え
ユーザー tanukidontanukidon
提出日時 2018-03-24 11:30:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 266 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 11,472 KB
実行使用メモリ 15,316 KB
最終ジャッジ日時 2023-09-07 08:23:57
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,012 KB
testcase_01 AC 84 ms
15,020 KB
testcase_02 AC 86 ms
15,160 KB
testcase_03 AC 84 ms
15,128 KB
testcase_04 AC 84 ms
15,316 KB
testcase_05 AC 87 ms
15,232 KB
testcase_06 AC 86 ms
15,060 KB
testcase_07 AC 85 ms
15,272 KB
testcase_08 AC 84 ms
15,236 KB
testcase_09 AC 84 ms
15,276 KB
testcase_10 AC 86 ms
15,272 KB
testcase_11 AC 85 ms
15,088 KB
testcase_12 AC 87 ms
15,088 KB
testcase_13 AC 85 ms
15,292 KB
testcase_14 AC 83 ms
15,268 KB
testcase_15 AC 85 ms
15,064 KB
testcase_16 AC 83 ms
15,124 KB
testcase_17 AC 84 ms
15,084 KB
testcase_18 AC 83 ms
15,280 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: possibly useless use of != in void context
Syntax OK

ソースコード

diff #

n = gets.chomp.split("").map(&:to_i)
a = n
b = 0
c = 0
d = 0
m = 0
n.size.times do |i|
  if n[0] == n.max
    n = n.drop(1)
    d += 1
  else n[0] !=n.max
    m = n.rindex(n.max) + d
    c = i
    b += 1
    break
  end
end
a[m],a[c] =a[c],a[m] if b == 1
puts a.join
0