1020 PAT
在编译器上运行没问题,提交显示编译错误
# include<stdio.h> # include<stdlib.h> struct YB { int a,b; double c; }yb[1000]; int cmp( const void *a ,const void *b) { return (*(YB *)a).c > (*(YB *)b).c ? -1 : 1; } int main() { int N,D,i; double sum; scanf("%d %d",&N,&D); for(i=0;i<N;i++) { scanf("%d",&yb[i].a); } for(i=0;i<N;i++) { scanf("%d",&yb[i].b); } for(i=0;i<N;i++) { yb[i].c = yb[i].b *1.0 / yb[i].a; } qsort(yb,N,sizeof(yb[0]),cmp); for(i=0;1;i++) { if(D - yb[i].a <= 0) { break; } sum = sum + yb[i].b; D = D - yb[i].a; } sum = sum + D*yb[i].c; printf("%.2lf",sum); return 0; }