結果

問題 No.2226 Hello, Forgotten World!
ユーザー tnakao0123tnakao0123
提出日時 2023-04-24 02:25:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 44,160 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 19:29:53
合計ジャッジ時間 998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 9 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2226.cc:  No.2226 Hello, Forgotten World! - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int L = 10;
const char T[] = "helloworld";

/* typedef */

/* global variables */

char s[MAX_N + 4], t[MAX_N + 4], mins[MAX_N + 4];

/* subroutines */

bool match(char w[]) {
  for (int i = 0; i < L; i++)
    if (w[i] != '?' && w[i] != T[i]) return false;
  return true;
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n;
    scanf("%d%s", &n, s);

    bool found = false;
    mins[0] = 'z' + 1, mins[1] = '\0';
    
    for (int k = n - L; k >= 0; k--)
      if (match(s + k)) {
	found = true;
	strcpy(t, s);
	for (int i = 0; i < L; i++) t[k + i] = T[i];
	for (int i = 0; i < n; i++)
	  if (t[i] == '?') t[i] = 'a';
	if (strcmp(mins, t) > 0) strcpy(mins, t);
      }

    if (found) puts(mins);
    else puts("-1");
  }
  return 0;
}
0