結果

問題 No.430 文字列検索
ユーザー aaaaaaaa
提出日時 2018-03-08 07:09:48
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 864 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 66,080 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-15 12:01:05
合計ジャッジ時間 16,078 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 627 ms
6,940 KB
testcase_02 TLE -
testcase_03 AC 1,271 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0