結果

問題 No.430 文字列検索
ユーザー DugongDugong
提出日時 2016-10-04 19:23:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 63,784 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 04:38:12
合計ジャッジ時間 1,753 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 75 ms
5,376 KB
testcase_02 AC 41 ms
5,376 KB
testcase_03 AC 54 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 26 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 78 ms
5,376 KB
testcase_12 AC 76 ms
5,376 KB
testcase_13 AC 76 ms
5,376 KB
testcase_14 AC 60 ms
5,376 KB
testcase_15 AC 53 ms
5,376 KB
testcase_16 AC 48 ms
5,376 KB
testcase_17 AC 45 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |   scanf("%s %d",s,&m);
      |   ~~~~~^~~~~~~~~~~~~~
main.cpp:17:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |     scanf("%s",c[i]);
      |     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<string>
#include<algorithm>
using namespace std;

char s[50001];
char c[5000][11];
int m,ans;
set<string> st;

int main(){
  scanf("%s %d",s,&m);
  for(int i=0;i<m;i++){
    scanf("%s",c[i]);
    string str(c[i]);
    st.insert(str);
  }
  int l = strlen(s);
  for(int i=0;i<l;i++){
    for(int j=1;j<=10&&i+j<=l;j++){
      char c = s[i+j];
      s[i+j] = '\0';
      string str(s+i); // attention!
      if(st.find(str)!=st.end()){
        ans++;
      }
      s[i+j] = c;
    }
  }
  printf("%d\n",ans);
  return 0;
}
0