結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-08 07:09:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 864 bytes |
| コンパイル時間 | 531 ms |
| コンパイル使用メモリ | 64,636 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-10 00:19:11 |
| 合計ジャッジ時間 | 18,576 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 11 TLE * 3 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// strに含まれるsubの数を返却する
int nSubstr(const string &str, const string &sub) {
int n = 0;
vector<int> idxs;
int ub = str.size() - sub.size() + 1;
for (int idx = 0; idx < ub; ++idx) {
if (str[idx] == sub[0]) {
idxs.push_back(idx);
}
}
for (const int &idx : idxs) {
if (sub.size() == 1) {
++n;
continue;
}
bool found = true;
for (int i = 1; i < sub.size(); ++i) {
if (str[idx + i] != sub[i]) {
found = false;
break;
}
}
if (found) ++n;
}
return n;
}
int main () {
int count = 0;
string str;
vector<string> subs;
int n;
cin >> str; cin >> n;
for (int i = 0; i < n; ++i) {
string tmp; cin >> tmp;
subs.push_back(tmp);
}
for (string sub : subs) {
count += nSubstr(str, sub);
}
cout << count << endl;
}