代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
typedef unsigned long long ull;
ull mod=212370440130137957;
ull prise=233317;
ull base=141;
ull hash(char s[15]){
ull len=strlen(s);
ull ans=0;
for(ull i=0;i<len;i++){
ans=(ans*base+(ull)(s[i]))%mod+prise;
}
return ans;
}
ull n;
char s1[12];
char s2[12];
struct qwq{
ull ans;
ull cnt;
bool e;
}a[100005];
bool cmp(qwq x,qwq y){
return x.ans<y.ans;
}
bool cmp2(qwq x,qwq y){
return x.cnt<y.cnt;
}
int main(){
cin>>n;
for(ull i=1;i<=n;i++){
cin>>s1>>s2;
a[i].cnt=i;
a[i].ans=hash(s1)+hash(s2);
}
sort(a+1,a+n+1,cmp);
for(ull i=1;i<=n;i++){
//cout<<a[i].ans<<"\n";
if(a[i].ans==a[i-1].ans)
a[i].e=0;
else
a[i].e=1;
}
sort(a+1,a+n+1,cmp2);
for(ull i=1;i<=n;i++){
//cout<<a[i].ans<<" ";
if(a[i].e==0)
cout<<"NO\n";
if(a[i].e==1)
cout<<"YES\n";
}
return 0;
}
错误信息:
编译错误:您提交的代码无法完成编译
a.cpp:37:12: error: reference to 'hash' is ambiguous
a[i].ans=hash(s1)+hash(s2);
^
a.cpp:10:5: note: candidate found by name lookup is 'hash'
int hash(char s[15]){
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/system_error:134:12: note: candidate found by name lookup is 'std::hash'
struct hash;
^
a.cpp:37:12: error: no viable constructor or deduction guide for deduction of template arguments of 'hash'
a[i].ans=hash(s1)+hash(s2);
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/functional_hash.h:58:12: note: candidate template ignored: could not match 'hash<_Tp>' against 'char *'
struct hash;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/functional_hash.h:58:12: note: candidate function template not viable: requires 0 arguments, but 1 was provided
a.cpp:37:21: error: reference to 'hash' is ambiguous
a[i].ans=hash(s1)+hash(s2);
^
a.cpp:10:5: note: candidate found by name lookup is 'hash'
int hash(char s[15]){
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/system_error:134:12: note: candidate found by name lookup is 'std::hash'
struct hash;
^
a.cpp:37:21: error: no viable constructor or deduction guide for deduction of template arguments of 'hash'
a[i].ans=hash(s1)+hash(s2);
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/functional_hash.h:58:12: note: candidate template ignored: could not match 'hash<_Tp>' against 'char *'
struct hash;
^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/functional_hash.h:58:12: note: candidate function template not viable: requires 0 arguments, but 1 was provided
4 errors generated.
DEVc++里运行正常,但到洛谷和其他oj的在线ide上编译就失败,求大佬更改!