| ||||||||||
| 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 | |||||||||
题目数据敢不敢放出来,这个读入有问题?#include <stdio.h>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN=12;
const int STEP=53;
const long MAXCOUNT=100000;
const long MAXMEMORY=3145739;
struct NODE
{
char language[MAXN];
long Dic;
};
/*
1600000
53, 97, 193, 389, 769,
1543, 3079, 6151, 12289, 24593,
49157, 98317, 196613, 393241, 786433,
1572869, 3145739, 6291469, 12582917, 25165843,
201326611, 402653189, 50331653, 100663319,
805306457, 1610612741, 3221225473ul, 4294967291ul
*/
NODE Heap[MAXMEMORY];
char words[MAXCOUNT+1][MAXN];
long c,top;
int cmp(NODE,NODE);
int main()
{
char str[1000];
c=0;
top=-1;
memset(Heap,0,sizeof(Heap));
memset(words,0,sizeof(words));
while (gets(str))
{
if (strlen(str)==0) break;
int blank=0;
while (str[blank]!=' ') blank++;
c++;
for (int i=0;i<blank;i++) words[c][i]=str[i];
words[c][blank]='\0';
//int *array; array= (int *)malloc(sizeof(int)*10)
//int *a; a=new int
top++;
Heap[top].Dic=c;
for (int i=blank+1;i<strlen(str);i++)
Heap[top].language[i-blank-1]=str[i];
Heap[top].language[strlen(str)-blank-1]='\0';
}
sort(Heap,Heap+top+1,cmp);
while(scanf("%s",str)!=EOF)
{
long l=0,r=top,mid;
while (r>=l)
{
mid=(l+r)/2;
int t=strcmp(Heap[mid].language,str);
if (t==0) break;
if (t<0) r=mid-1;
if (t>0) l=mid+1;
}
if (strcmp(Heap[mid].language,str)==0)
printf("%s\n",words[Heap[mid].Dic]);
else
printf("eh\n");
}
return 0;
}
int cmp(NODE A,NODE B)
{
return strcmp(A.language,B.language);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator