結果

問題 No.254 文字列の構成
ユーザー yuruhiya
提出日時 2021-07-29 14:43:55
言語 Crystal
(1.14.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 366 bytes
コンパイル時間 12,751 ms
コンパイル使用メモリ 294,492 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 12:01:07
合計ジャッジ時間 14,591 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def square(n : Int32)
  sqrt = Math.sqrt(n).to_i + 1
  while sqrt * sqrt > n
    sqrt -= 1
  end
  sqrt
end

n = read_line.to_i
a = [] of Int32
while n > 0
  s = square(n)
  a << s - 1
  n -= s * s
end

now = 'a'
puts a.map_with_index { |x, i|
  if x == 0
    now.tap { now += 1 }
  else
    c1, c2 = now, now + 1
    now += 2
    "#{c1}#{c2}" * x + c1
  end
}.join
0