求大神给改改
这是原题
这是我的代码
程序代码:
#include "stdio.h" #include <stdlib.h> #define M 500 typedef struct { int r[M],n,k; }JD; void scanfxl(JD *X){ int i,a; for(i=1;i<M;i++) { scanf("%d",&X->r[i]); if(getchar()=='\n') break; } X->n=i; scanf("%d",&X->k); } void binsrch(JD x,int num) { int low,high,mid,found,a[M],i; //low是下界,high是上界,mid是中间位置 low=1; high=x.n; found=0; //found是查找标志:找到为1;没找到为0 while((low<=high)&&(found==0)) { mid=(low+high)/2; a[num]=mid; num++; if(x.k==x.r[mid]) { found=1; break; } else if(x.k>x.r[mid]) { low=mid+1; } else { high=mid-1;} } for(i=1;i<num-1;i++) printf("%d ",a[i]); printf("%d",a[num-1]); printf("\n"); if(found==1) printf("%d",mid); else printf("%d",found); } int main(){ JD x; int num; while(1) { num=1; scanfxl(&x); binsrch(x,num); printf("\n"); if (getchar() == '\n') continue; else break; } return 0;}
无论怎么改 一直是格式错误 求大神找找错误