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.h> #include<stdlib.h> char value[100000][25]; int compare(const void*a,const void*b) {return strcmp((char*)a,(char*)b);} int main() { char english[25],str[11],dialect[11]; int index,i=0; while(1){ english[0]=(char)getchar(); if(english[0]=='\n')break; scanf("%s %s",english+1,str); getchar(); strcpy(value[i],str); for(int j=strlen(str);j<11;j++) value[i][j]='0'; strcat(value[i],english); i++; } qsort(value,i,25,compare); while(scanf("%s",dialect)!=EOF){ for(int j=strlen(dialect);j<10;j++) dialect[j]='0'; int left=0,right=i-1,middle=(left+right)/2; while(left!=right) { middle=(left+right)/2; if(strncmp(value[middle],dialect,10)>0) {right=middle-1;} else if(strncmp(value[middle],dialect,10)<0) {left=middle+1;} else break; } printf("%s\n",value[middle][11]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator