折半查找。。。求教大神
#include<stdio.h>int main()
{
int num[41],score[41],search,i,j,k,tem;
for(i=1;;i++)
{
scanf("%d%d",&num[i],&score[i]);
if((num[i]==-1)&&(score[i]==-1))
break;
}
i--;
for(j=1;j<i;j++)
{
for(k=j+1;k<=i;k++)
if(num[j]>num[k])
{
tem=num[k];
num[k]=num[j];
num[j]=tem;
tem=score[k];
score[k]=score[j];
score[j]=tem;
}
}
scanf("%d",&search);
for(j=0;j<=i;j++)
if(search==num[i/2])
{
printf("%d",score[i/2]);
break;
}
else if(search<num[i/2])
{
i=i/2;
}
else if(search>num[i/2])
{
i=i/2+i/4;
}
return 0;
}