結果

問題 No.254 文字列の構成
ユーザー siman
提出日時 2022-03-10 01:13:31
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 527 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-09-14 02:39:05
合計ジャッジ時間 8,770 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 1 WA * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

def build_str(ch, len, is_first = false)
  if is_first
    res = ch * len
    ch.succ!
  else
    res = ch * len
    ch.succ!
    res << ch
    ch.succ!
  end

  res
end

cur = 'a'
is_first = true
len = 0
ans = ''

30.times do |i|
  if N[i] == 0
    if is_first
      str = build_str(cur, i, true)
      is_first = false
      ans << str
    end
  else
    if is_first
      len += 1
    else
      str = build_str(cur, i)
      ans << str
    end
  end
end

if ans[-1] <= 'z'
  puts ans
else
  puts 'sushi'
end
0