C语言实现美团下单优惠系统(2018CodeM Q1)

#include <stdio.h>

typedef struct

float money;

int flag;

}good;

typedef struct

float price;

float count;

}discount;

int main()

int n,m;

while(~scanf(“%d”,&n))

int good_num = n;

scanf(“%d”,&m);

discount d[10];

int discount_num = m;

good g[10];

for(int i = 0;i<good_num;i++)

scanf(“%f”,&(g[i].money));

scanf(“%d”,&(g[i].flag));

for(int i = 0;i<discount_num;i++)

scanf(“%f”,&(d[i].price));

scanf(“%f”,&(d[i].count));

float sum = 0;//不使用优惠的总价格

float sum_good1 = 0;//八折后物品的价格

float sum_good2 = 0;//使用满减后的价格

for(int i = 0;i<good_num;i++)

sum+=g[i].money;

//printf(“%f\n”,sum);

if(g[i].flag==1)sum_good1+=g[i].money*0.8;

else sum_good1+=g[i].money;

int real_count = 0;

for(int i = 0;i<discount_num;i++)

if(sum>=d[i].price)

if(d[i].count>real_count)real_count = d[i].count;

sum_good2 = sum – real_count;

float real_sum = sum;

if(real_sum>=sum_good1) real_sum=sum_good1;

if(real_sum>=sum_good2) real_sum=sum_good2;

printf(“%.2f\n”,real_sum);

return 0;

原文链接:https://blog.csdn.net/li99yangg/article/details/80602002?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165277499316781432921534%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165277499316781432921534&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-9-80602002-null-null.nonecase&utm_term=%E4%BC%98%E6%83%A0

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
文明发言,共建和谐米科社区
提交
头像

昵称

取消
昵称表情图片