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

大牛帮忙看看为什么WA了呢 ??

Posted by ACM_henry at 2008-10-29 18:28:47 on Problem 2872
#include <iostream>
using namespace std;
const int prim=1000001;
char q[51000][300];
struct h
{
	int key;
	int num;	
}hash[prim];
void insert(long v)
{
    long key=v; while(key<0) key+=prim;
    if(key>=prim) key=key%prim;
    while(hash[key].num!=0)
	{
         if(hash[key].key==v){ hash[key].num++; return; }
         key=(key+1)%prim;            
    }     
    hash[key].num=1; hash[key].key=v;
}

int search(long v)
{
    long key=v; while(key<0) key+=prim;
    if(key>=prim) key=key%prim;
    while(hash[key].num!=0)
	{
         if(hash[key].key==v) return hash[key].num;
         key=(key+1)%prim;                      
    }
    return 0;
}

int main()
{
	char p[300];
	
	int num;
	scanf("%d",&num);
	int i,j;
	int sum;
	for(i=0;i<num;i++)
	{
		sum=0;
		scanf("%s",p);
		for(j=0;j<strlen(p);j++)
		{
			sum=sum*26+p[j]-'a'+1;
			sum%=prim;
		}
		insert(sum);
	}
	int aim=0;
	int que;
	scanf("%d",&que);
	int k;
	for(k=0;k<que;k++)
	{
	aim=0;
	bool flag=0;
	while(1)
	{
		sum=0;
		scanf("%s",q[aim++]);
		if(q[aim-1][0]=='-'&&q[aim-1][1]=='1')
		{
			break;
		}
		for(i=0;i<strlen(q[aim-1]);i++)
		{
			sum=sum*26+q[aim-1][i]-'a'+1;
			sum%=prim;
		}
		if(search(sum)==0)
		{
			flag=1;
		}

	}
	if(flag==0)
	{
		printf("Email %d is spelled correctly.\n",k+1);
		printf("End of Output\n");
	}
	else 
	{
		printf("Email %d is not spelled correctly.\n",k+1);
		for(i=0;i<aim-1;i++)
		{
			sum=0;
			for(j=0;j<strlen(q[i]);j++)
			{
				sum=sum*26+q[i][j]-'a'+1;
				sum%=prim;
			}
			if(search(sum)==0)
			{
				printf("%s\n",q[i]);
			}
		}
		printf("End of Output\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