30分RE求调
查看原帖
30分RE求调
1454736
xuanzeiliza楼主2024/11/20 19:18
#include<iostream>
#include<string>
#define M 10010 * 50
using namespace std;

int dictree[M][30];
int _end[M];
int _check[M];
int mark = 1;

void _insert(string s)
{
	int nxt = 1;
	for (int i = 0; i < s.size(); i++) {
		int ch = s[i] - 'a';
		if (!dictree[nxt][ch]) {
			dictree[nxt][ch] = ++mark;
		}
		nxt = dictree[nxt][ch];
	}
	_end[nxt] = 1;
}

int _find(string s)
{
	int nxt = 1;
	for (int i = 0; i < s.size(); i++)
	{
		int ch = s[i] - 'a';
		if (!dictree[nxt][ch])return 0;
		nxt = dictree[nxt][ch];
	}
	if (!_end[nxt])return 0;
	else {
		if (_check[nxt]) return 2;
		else {
			_check[nxt] = 1;
			return 1;
		}
	}
}

int main()
{
	int _;
	cin >> _;
	while (_--) {
		string s;
		cin >> s;
		_insert(s);
	}
	cin >> _;
	while (_--)
	{
		string s;
		cin >> s;
		int judge = _find(s);
		if (judge == 1)cout << "OK" << endl;
		else if (judge == 2)cout << "REPEAT" << endl;
		else cout << "WRONG" << endl;
	}
}

为什么一直re啊,数组开的大小也是够的,还是显示访问不合法的内存(哭)

2024/11/20 19:18
加载中...