結果

問題 No.238 Mr. K's Another Gift
ユーザー siman
提出日時 2021-11-02 11:11:04
言語 Ruby
(3.4.1)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 347 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-10-11 09:30:56
合計ジャッジ時間 6,041 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

S = gets.chomp
RS = S.reverse
N = S.size

if S == RS
  l = N / 2
  S.insert(l, S[l])

  puts S
else
  idx = (0...N).find { |i| S[i] != RS[i] }
  r_idx = N - idx - 1
  s = S.dup
  s.insert(r_idx + 1, S[idx])
  rs = S.dup
  rs.insert(idx, S[r_idx])

  if s == s.reverse
    puts s
  elsif rs == rs.reverse
    puts rs
  else
    puts 'NA'
  end
end
0