某团购网某自助烤肉店周年庆。正常自助58元一位。周年庆团购,团购人数越多打折越多,优惠如下:
总团购人数 折扣
0-50 全价
51-100 9.0折
101-150 8.5折
151-200 8.0折
大于200 7.5折
另有网站礼品券,面额100元减10元,200元减30元,500元减80元可以使用(一次只能使用1张且无最低消费要求)。
依次输入已参加团购人数、本次购买人数和礼品券面额。打折和礼品券不能同时使用,请编程计算本次消费打折划算,还是使用礼品券划算。(输出0代表无法判断,1代表打折,2代表礼品券)
输入:
200,3,100
输出:
1
输入:
2,3,0
输出:
0
代码如下:
#include <stdio.h>
int main()
{
int tuangou_num = 0; //已经团购人数
int thistime_num = 0; //当前要团购人数
int daijinquan = 0; //当前拥有的代金券
scanf("%d,%d,%d", &tuangou_num, &thistime_num, &daijinquan); //1
int currentnum = 0;
currentnum = tuangou_num + thistime_num; //计算之前团购人数+这次人数 //1
double money_tuangou = 0; //使用团购的实际消费
if (thistime_num <= 0)
{
printf("0");
return 0;
}
if (currentnum <= 50) //当当前人数超过某一当,计算折扣 //1
money_tuangou = thistime_num * 58; //1
if (currentnum >= 51 && currentnum <= 100) //1
money_tuangou = thistime_num * 58 * 0.9;
if (currentnum >= 101 && currentnum <= 150)
money_tuangou = thistime_num * 58 * 0.85;
if (currentnum >= 151 && currentnum <= 200)
money_tuangou = thistime_num * 58 * 0.8;
if (currentnum > 200) //1
money_tuangou = thistime_num * 58 * 0.75;
double money_daijinquan = 0; //使用代金券最后的实际消费
money_daijinquan = 58 * thistime_num;
if (daijinquan == 100) //1
money_daijinquan = money_daijinquan - 10; //1
if (daijinquan == 200)
money_daijinquan = money_daijinquan - 30;
if (daijinquan == 500)
money_daijinquan = money_daijinquan - 80;
if (money_tuangou < money_daijinquan)
printf("1"); //1
else if (money_tuangou > money_daijinquan)
printf("2"); //1
else
printf("0");
return 0;
}