結果

問題 No.2226 Hello, Forgotten World!
ユーザー 👑 chro_96chro_96
提出日時 2023-02-24 21:54:04
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 29,592 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 06:10:19
合計ジャッジ時間 837 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 10 ms
4,352 KB
testcase_02 AC 12 ms
4,352 KB
testcase_03 AC 8 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 7 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 5 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp_char_arr (const void *a, const void *b) {
  return strcmp((char *)a, (char *)b);
}

int main () {
  int t = 0;
  int n = 0;
  char s[1011] = "";
    
  int res = 0;
  
  char ans[1000][1001] = {};
  char hw[11] = "helloworld";
  
  res = scanf("%d", &t);
  while (t > 0) {
    res = scanf("%d", &n);
    res = scanf("%s", s);
    for (int i = 0; i < n; i++) {
      int is_ok = 1;
      for (int j = 0; j < 10; j++) {
        if (s[i+j] != '?' && s[i+j] != hw[j]) {
          is_ok = 0;
        }
      }
      if (is_ok > 0) {
        for (int j = 0; j < n; j++) {
          if (s[j] == '?') {
            ans[i][j] = 'a';
          } else {
            ans[i][j] = s[j];
          }
        }
        for (int j = 0; j < 10; j++) {
          ans[i][i+j] = hw[j];
        }
      } else {
        for (int j = 0; j < n; j++) {
          ans[i][j] = '~';
        }
      }
      ans[i][n] = '\0';
    }
    qsort(ans, n, sizeof(char)*1001, cmp_char_arr);
    if (ans[0][0] == '~') {
      printf("-1\n");
    } else {
      printf("%s\n", ans[0]);
    }
    t--;
  }
  
  return 0;
}
0