結果

問題 No.430 文字列検索
ユーザー mbanmban
提出日時 2017-02-09 13:58:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 677 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 71,140 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 20:16:57
合計ジャッジ時間 8,319 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 677 ms
4,376 KB
testcase_02 AC 673 ms
4,380 KB
testcase_03 AC 672 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 666 ms
4,380 KB
testcase_12 AC 669 ms
4,380 KB
testcase_13 AC 676 ms
4,380 KB
testcase_14 AC 670 ms
4,380 KB
testcase_15 AC 668 ms
4,376 KB
testcase_16 AC 672 ms
4,376 KB
testcase_17 AC 674 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<map>

#define ABC "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

using namespace std;

string s;
int n;
string *c;
int d[100000];
unsigned int i, j, k, anser = 0;



void scan() {
	cin >> s;
	cin >> n;
	c = new string[n];
	for (i = 0; i < n; i++)
	{
		cin >> c[i];
	}

}

long long tolong(string ss) {
	long long result = 0;
	long long p = 1;
	for (j = 0; j < ss.size(); j++)
	{
		result += d[ss[j]] * p;
		p *= 26;
	}
	return result;
}


int main(void) {
	scan();
	for (i = 0; i < 26; i++)
	{
		d[ABC[i]] = i;
	}
	for (i = 0; i < n; i++)
	{
		long long search = tolong(c[i]);
		long long p = 1, l = 0;
		for (j = 0; j < c[i].size() - 1; j++)
		{
			l += d[s[j]] * p;
			p *= 26;
		}
		for (j = c[i].size() - 1; j < s.size(); j++)
		{
			l += d[s[j]] * p;
			if (l == search) {
				anser++;
			}
			l /= 26;
		}
	}
	cout << anser << endl;
	return 0;
}
0