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???请牛人们帮我看一下,和网上的一个程序几乎一模一样,为什么他的ac我的wa??!!

Posted by qinwang at 2009-11-15 01:54:19 on Problem 2503
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
char en[30];
struct dic
{
	char s1[11];
	char s2[11];
}str[100001];
bool cmp(struct dic a,struct dic b)
{
	return (strcmp(a.s2,b.s2)<0);
}
int bsearch(char *p,int head,int end)
{
	int mid=0;
	while(head<=end)
	{
		mid=(head+end)/2;
		if(strcmp(p,str[mid].s2)<0)
			end=mid-1;
		else
		{
			if(strcmp(p,str[mid].s2)>0)
				head=mid+1;
			else 
				return mid;
		}
	}
	return -1;
}
int main()
{
	int i=0,j=0;
	char a[11];
	while(gets(en)&&en[0]!='\0')
	{
		sscanf(en,"%s %s",str[i].s1,str[i].s2);
		i++;
	}
	sort(str,str+i,cmp);
	while(scanf("%s",a)!=EOF)
	{
		int n;
		n=bsearch(a,0,i-1);
		if(n==-1)
			printf("en\n");
		else
			printf("%s\n",str[n].s1);
	}
	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