| ||||||||||
| 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 | |||||||||
为什么我的程序老是wa???请牛人们帮我看一下,和网上的一个程序几乎一模一样,为什么他的ac我的wa??!!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator