PAT B1020

来源:互联网 发布:淘宝女装店扒皮aviva 编辑:程序博客网 时间:2024/06/05 18:46
include <stdio.h>struct mooncake{double store;double sell;double price;}cake[1010];int main(){  int n,i,j;  double ans=0,D,temp,temp1,temp2;  scanf("%d%lf",&n,&D);  for(i=0;i<n;i++)  scanf("%lf",&cake[i].store);  for(i=0;i<n;i++)  {    scanf("%lf",&cake[i].sell);    cake[i].price=cake[i].sell/cake[i].store;    }  for(i=0;i<n-1;i++)    for(j=i+1;j<n;j++)      if(cake[i].price<cake[j].price)      {        temp=cake[i].price;        cake[i].price=cake[j].price;        cake[j].price=temp;        temp1=cake[i].sell;        cake[i].sell=cake[j].sell;        cake[j].sell=temp1;        temp2=cake[i].store;        cake[i].store=cake[j].store;        cake[j].store=temp2;      }  //qsort(cake,n,sizeof(struct mooncake),comp);  for(i=0;i<n;i++)  {    if(cake[i].store<=D)    {      D-=cake[i].store;      ans+=cake[i].sell;    }      else      {        ans+=cake[i].price*D;        break;      }  }printf("%.2f\n",ans);return 0;}
0 0
原创粉丝点击