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

这样做怎么内存出错啊?

Posted by sunnvya at 2006-09-21 08:53:57 on Problem 2503
#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:
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