社区讨论
关于c++版本的提问
P3370【模板】字符串哈希参与者 4已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mhju7srg
- 此快照首次捕获于
- 2025/11/04 08:35 4 个月前
- 此快照最后确认于
- 2025/11/04 08:35 4 个月前
为什么以下代码在c++11标准下会编译错误:
58行 8列 [Error] reference to 'hash' is ambiguous
41行 5列 [Note] candidates are: ull hash(char*)
但是在c++98标准又能正确运行且AC?
CPP58行 8列 [Error] reference to 'hash' is ambiguous
41行 5列 [Note] candidates are: ull hash(char*)
但是在c++98标准又能正确运行且AC?
#include <bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;
ull base=131;//进制
ull mod=9999999967;
ull a[1000005];
char s[1000005];
inline int read()
{
bool f=true;
int g=0;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
{
f=false;
}
c=getchar();
}
while(c>='0'&&c<='9')
{
g=g*10+(c&15);
c=getchar();
}
return f?g:(~g+1);
}
inline void write(int n)
{
if(n<0)
{
putchar('-');
n=(~n+1);
}
if(n>9)
{
write(n/10);
}
putchar(n%10+'0');
}
ull hash(char a[])//就是这里
{
int len=strlen(a);
ull ans=0;
for(int i=0;i<len;i++)
{
ans=(ans*base+(ull)a[i])%mod;
}
return ans;
}
int main()
{
int n=read();
int ans=0;
for(int i=1;i<=n;i++)
{
scanf("%s",&s);
a[i]=hash(s);//还有这里
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
if(a[i]!=a[i+1])
{
ans++;
}
}
write(ans);
return 0;
}
蒟蒻不太懂求解答:(
回复
共 3 条回复,欢迎继续交流。
正在加载回复...