結果

問題 No.2226 Hello, Forgotten World!
ユーザー simansiman
提出日時 2023-02-26 20:56:43
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 558 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 11,140 KB
実行使用メモリ 15,380 KB
最終ジャッジ日時 2023-10-12 10:58:42
合計ジャッジ時間 1,967 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,228 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:40: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

T = gets.to_i

target = 'helloworld'

T.times do
  n = gets.to_i
  s = gets.chomp
  best_idx = -1

  (n - 10).downto(0) do |i|
    ok = true
    idx = 0

    while ok && idx < 10
      if target[idx] == s[i + idx] || s[i + idx] == '?'
        # NOOP
      else
        ok = false
      end

      idx += 1
    end

    if ok
      best_idx = i
      break
    end
  end

  if best_idx != -1
    10.times do |i|
      if s[best_idx + i] == '?'
        s[best_idx + i] = target[i]
      end
    end

    s.tr!('?', 'a')
    puts s
  else
    puts -1
  end
end
0