标签:cas 代码 end ios ace 转化 输入 include 优惠
一,问题描述
本数 折扣
2 5%
3 10%
4 20%
5 25%
二、设计思想
易知购买五本时的最大优惠,大于五本时可以转化为5+n。
三、代码实现
#include<iostream> using namespace std; double num1(int a){ double sum1; switch(a%5) { case 1: sum1=5*8*0.75+8;break; case 2: sum1=5*8*0.75+2*8*0.95;break; case 3: sum1=4*8*0.8+4*8*0.8;break; case 4: sum1=5*8*0.75+4*8*0.8;break; } return sum1; } int main(int argc, char* argv[]) { int num; double sum; cout<<"请输入您要购买的本数:"; cin>>num; if(num<=5) { switch(num) { case 1: sum=8;break; case 2: sum=2*8*0.95;break; case 3: sum=3*8*0.9;break; case 4: sum=4*8*0.8;break; case 5: sum=5*8*0.75;break; } } if((num>5)&&(num<10)) { sum=num1(num); } if(num>9) { switch(num%5) { case 0: sum=(num/5)*8*5*0.75;break; case 1: sum=(num/5-1)*5*8*0.75+num1(6);break; case 2: sum=(num/5-1)*8*5*0.75+num1(7);break; case 3: sum=(num/5-1)*8*5*0.75+num1(8);break; case 4: sum=(num/5-1)*8*5*0.75+num1(9);break; } } cout<<"最大折扣价为:"<<sum; cout<<endl; return 0; }
四、实现截图
标签:cas 代码 end ios ace 转化 输入 include 优惠
原文地址:http://www.cnblogs.com/a1264393659/p/6961942.html