結果

問題 No.430 文字列検索
ユーザー mbanmban
提出日時 2017-02-09 13:32:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 881 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 75,932 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-26 20:13:10
合計ジャッジ時間 5,009 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
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<map>

#define ABC "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

using namespace std;

string s;
int n;
string *c;
map<char, int>d;
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