社区讨论
双哈希编译错误求帮助
学术版参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi6wsnuz
- 此快照首次捕获于
- 2025/11/20 12:06 4 个月前
- 此快照最后确认于
- 2025/11/20 12:06 4 个月前
如题,编译机说没有找到hash1,和hash2
CPP//
// main.cpp
// 【模板】双哈希
//
// Created by winstar919 on 2018/9/1.
// Copyright © 2018年 tatsumaki. All rights reserved.
//
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
int base=131;
using namespace std;
struct data{
long long x,y;
}a[10010];
char s[10010];
int n;
bool cmp(data a,data b ){
return a.x<b.x;
}
long long mod1=19260817,mod2=19660813;
long long hash1(char s[ ]){
long long ans = 0;
int len=strlen(s);
for(int i = 0; i < n; i ++){
ans = (ans*base+(long long )s[i]) % mod1;
}
return ans;
}
long long hash2(char s[ ]){
long long ans = 0;
int len = strlen(s);
for(int i = 0; i < n; i ++)
ans = (ans * base + (long long )s[i])*mod2;
return ans;
}
int main() {
int ans=0;
scanf("%d",&n);
for(int i = 0; i < n; i ++){
scanf("%s",&s[i]);
a[i].x=hash1(s[i]);
a[i].y=hash2(s[i]);
}
sort(a,a+n,cmp);
for(int i = 1; i < n; i ++){
if(a[i].x != a[i - 1].x || a[i].y != a[i - 1].y)
ans++;
}
printf("%d",ans);
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...