結果

問題 No.430 文字列検索
ユーザー DialBird
提出日時 2016-10-20 14:07:54
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 738 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 20,864 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-10 00:11:09
合計ジャッジ時間 5,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:17:3: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   fscanf(stdin, "%s", S);
      |   ^~~~~~~~~~~~~~~~~~~~~~
main.c:18:3: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   fscanf(stdin, "%d", &M);
      |   ^~~~~~~~~~~~~~~~~~~~~~~
main.c:24:5: warning: ignoring return value of ‘fscanf’ 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 = (char*)xmalloc(50001);
  int M;
  fscanf(stdin, "%s", S);
  fscanf(stdin, "%d", &M);
  int i;
  char *point;
  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(S);
  printf("%d\n", count);
  exit(0);
}
0