結果

問題 No.430 文字列検索
ユーザー kurenai3110kurenai3110
提出日時 2016-10-03 01:06:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 856 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 76,856 KB
実行使用メモリ 14,008 KB
最終ジャッジ日時 2024-05-01 11:10:07
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int m; cin >> m;
	int ans = 0;

	for (int i = 0; i < m; i++) {
		string target; cin >> target;
		if (target.size() > s.size())continue;
		long long hash = 0,target_hash=0;
		for (int j = 0; j < target.size(); j++) target_hash += (target[j] - 'A'+1)*pow(26, j);
		for (int j = 0; j < target.size(); j++) hash += (s[j] - 'A'+1)*pow(26, j);
		if (hash == target_hash)ans++;
		cout << hash << target_hash << endl;
		for (int j = target.size(); j < s.size(); j++) {
			hash -= (s[j - target.size()] - 'A' + 1);
			hash /= 26;
			hash += (s[j] - 'A' + 1)*pow(26, target.size() - 1);
			if (hash == target_hash)ans++;
		}
	}

	cout << ans << endl;

	return 0;
}
0