求大佬看一下我这个为什么有三个点RE了
查看原帖
求大佬看一下我这个为什么有三个点RE了
833168
7546391a楼主2022/11/5 18:28
#include<iostream>
#include<string>
using namespace std;
typedef unsigned long long ull;
const int N = 2000;
ull p[N], h[N];
const int base = 131;
int n;

ull hash1(string a, int max1)
{
	ull sum = 0;
	for (int i = 1; i < max1; i++)
	{
		if (a[i] >= '0' && a[i] <= '9')
			sum += sum * base + a[i] - '0' + 1;
		if (a[i] >= 'a' && a[i] <= 'z')
			sum += sum * base + a[i] - 'a' + 11;
		if (a[i] >= 'A' && a[i] <= 'Z')
			sum += sum * base + a[i] - 'A' + 37;
	}
	return sum;
}
int main()
{
	cin >> n;
	p[0] = 1;
	for (int i = 1; i <= 1600; i++)
	{
		p[i] = p[i - 1] * base;
	}
	int k = 0;
	while (n--)
	{
		string str;
		cin >> str;
		ull t = hash1(str, str.size());
		int flag = 1;
		for (int i = 0; i < k; i++)
		{
			if (h[i] == t)
			{
				flag = 0;
				break;
			}
		}
		if (flag)
			h[k++] = t;
	}

	cout << k;
}

2022/11/5 18:28
加载中...