結果

問題 No.927 Second Permutation
ユーザー Takuya Noguchi
提出日時 2020-06-27 13:29:51
言語 Ruby
(3.4.1)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 278 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 24,704 KB
最終ジャッジ日時 2024-07-05 09:04:06
合計ジャッジ時間 5,157 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:4: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

X = gets.chomp

if X.chars.uniq.size == 1
  puts -1
else
  nums = X.chars.sort_by { |n| -n.to_i }
  (nums.size - 1).downto(1) do |i|
    next if nums[i] == nums[i - 1]

    nums[i], nums[i - 1] = nums[i - 1], nums[i]

    break
  end

  puts nums[0] == '0' ? -1 : nums.join
end
0