Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我这叫hash吧,但总是runtime error,大虾看一看

Posted by fjnu_jxd_010 at 2005-07-31 23:06:04 on Problem 2503
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator