这怎么过的??
查看原帖
这怎么过的??
524380
Ignatius_楼主2021/6/22 18:14

rt 我的哈希没有取模,但 intint 过了。

#include <bits/stdc++.h>
using namespace std;
namespace HMFS{
	const int base=233;
	const int mod=1e9+7;
	int n;
	set<int> s;
	int get_hash(string s) {
		int len=s.length(),res=1;
		for(int i=0;i<len;i++) {
			res=res*base+s[i];
		}
		return res;
	}
	void work() {
		cin>>n;
		for(int i=1;i<=n;i++) {
			string ss;
			cin>>ss;
			s.insert(get_hash(ss));
		}
		cout<<s.size();
	}
}
int main() {
	return HMFS::work(),0;
}
2021/6/22 18:14
加载中...