結果

問題 No.430 文字列検索
ユーザー DialBirdDialBird
提出日時 2016-10-20 07:04:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 708 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 24,064 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 04:44:15
合計ジャッジ時間 4,915 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 22 ms
5,376 KB
testcase_02 AC 499 ms
5,376 KB
testcase_03 AC 396 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 301 ms
5,376 KB
testcase_12 AC 325 ms
5,376 KB
testcase_13 AC 299 ms
5,376 KB
testcase_14 AC 397 ms
5,376 KB
testcase_15 AC 708 ms
5,376 KB
testcase_16 AC 560 ms
5,376 KB
testcase_17 AC 533 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:17:9: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   fscanf(stdin, "%s", S);
      |   ~~~~~~^~~~~~~~~~~~~~~~
main.cpp:18:9: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   fscanf(stdin, "%d", &M);
      |   ~~~~~~^~~~~~~~~~~~~~~~~
main.cpp:24:11: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     fscanf(stdin, "%s", str);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

static void *xmalloc(size_t size){
  void *m = malloc(size);
  if (!m) {
    perror("malloc()");
    exit(1);
  }
  return m;
}

int main(int argc, char *argv[]){
  char S[50001];
  int M;
  fscanf(stdin, "%s", S);
  fscanf(stdin, "%d", &M);
  int i;
  char *point = (char*)xmalloc(sizeof(char*));
  char str[11];
  int count = 0;
  for (i=0;i<M;i++) {
    fscanf(stdin, "%s", str);
    point = S;
    while ((point = strstr(point, str)) != NULL) {
      count++;
      point += 1;
    }
  }
  free(point);
  printf("%d\n", count);
  exit(0);
}
0