浙大PAT 1070题 1070. Mooncake

#include
#include
typedef struct NodeType{
	float amount;
	float price;
	float profit;
}Node;
Node node[1005];
int cmp(const void* ta,const void* tb){
	Node* a=(Node*)ta;
	Node* b=(Node*)tb;
	return b->profit>a->profit;//don't use b->profit-a->profit,beause the result is float-float,but the return is int.
}

int main(){
	int i,n;
	float d;
	scanf("%d %f",&n,&d);
	for(i=0;i0&&inode[i].amount){
			total=total+node[i].price;
			d=d-node[i].amount;
		}
		else{
			total=total+d/node[i].amount*node[i].price;
			d=0;
		}
		i++;
	}
	printf("%.2f\n",total);
	return 0;
}

你可能感兴趣的:(浙大pat)