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 |
救命啊~~为什么老是Runtime Error!用的hash#include <stdio.h> #include <string.h> #define PRIME 99991 #define MAX 100001 int flag[MAX]; char foreign[MAX][11]; char english[MAX][11]; int main() { int i, len_fre, sum, d, msg_len; char c, message[11], eng[11], frn[11]; memset(flag, 0, sizeof(flag)); //freopen("input.txt", "r", stdin); while ((c=getchar())!='\n'){ //读入数据 i=0; while (c!=' '){ eng[i++]=c; c=getchar(); } eng[i++]='\0'; c=getchar(); i=0; while (c!='\n'){ frn[i++]=c; c=getchar(); } frn[i++]='\0'; //对frn[]进行hash处理 len_fre=strlen(frn); sum=0; for (i=0;i<len_fre;i++){ sum+=frn[i]*frn[i]; } sum%=PRIME; d=5; while (flag[sum]==1){ sum+=d*d; sum%=PRIME; d++; } strcpy(english[sum], eng); strcpy(foreign[sum], frn); flag[sum]=1; } //查找 while (scanf("%s", message)!=EOF){ sum=0; msg_len=strlen(message); for (i=0;i<msg_len;i++){ sum+=message[i]*message[i]; } d=5; sum%=PRIME; while (flag[sum]!=0 && strcmp(message, foreign[sum])!=0){ sum+=d*d; d++; sum%=PRIME; } if (flag[sum]==1){ printf("%s\n", english[sum]); } else{ printf("eh\n"); } } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator