| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我这叫hash吧,但总是runtime error,大虾看一看In Reply To:有时间写个Trie吧 Posted by:frkstyc at 2005-07-20 23:44:13 #include<iostream>
#include<string>
using namespace std;
string c[300000],e[300000];
int main()
{
int t,n,i;
char a1[200];
string a,b;int k=213313;
//if(c[1]=="")
//{cout<<"23";return 0;}
while(gets(a1)&&a1[0]!='\0')
{a=a1;
for(i=0;a[i]!=' ';i++)
;
int na=i;
b=a.substr(na+1);
a=a.substr(0,na);
//cout<<b<<endl<<a<<endl;
n=b.length();
if(n>=3)
t=(b[0]+b[n-1]+b[n-2])%213313;
else t=3*b[0]%213313;
if(c[t]=="")
{c[t]=b;e[t]=a;}
else {c[++k]=b;e[k]=a;}
}
// cout<<"sfds";
while(scanf("%s",a1)==1)
{
n=strlen(a1);
int flag=0;
if(n>=3)
t=(a1[0]+a1[n-1]+a1[n-2])%213313;
else t=3*a1[0]%213313;
if(c[t]==a1)
printf("%s\n",e[t]);
else
{
for(i=213314;i<=k;i++)
if(c[i]==a1)
{flag=1;
printf("%s\n",e[i]);
break;
}
if(flag==0)
printf("eh\n");
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator