結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-10-20 07:04:46 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 733 ms / 2,000 ms | 
| コード長 | 604 bytes | 
| コンパイル時間 | 203 ms | 
| コンパイル使用メモリ | 23,808 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:11:04 | 
| 合計ジャッジ時間 | 4,868 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
コンパイルメッセージ
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);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~
            
            ソースコード
#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);
}
            
            
            
        