思路:只有8这个数特殊,3+5>4+4,其他的只要除5取余即可。
我偷了个懒,直接罗列if...
#include <iostream> using namespace std; void main() { int n; int i; cout<<"请输入本数:"<<endl; cin>>n; i = n/5; if(n<5) { if(n==1) cout<<"最低价格为8元"<<endl; if(n==2) cout<<"最低价格为"<<n*8*0.95<< "元"<<endl; if(n==3) cout<<"最低价格为"<<n*8*0.9<< "元"<<endl; if(n==4) cout<<"最低价格为"<<n*8*0.8<< "元"<<endl; } else { if(n%5==0) { cout<<i<<"套5本的"<<endl; cout<<"最低价格为:"<<i*8*5*0.75<< endl; } if(n%5==1) { cout<<i<<"套5本"<<endl; cout<<"加"<<n%5<<"本"<<endl; cout<<"最低价格为:"<<i*8*5*0.75+(n%5)*8<<endl; } if(n%5==2) { cout<<i<<"套5本"<<endl; cout<<"加"<<n%5<<"本"<<endl; cout<<"最低价格为:"<<i*8*5*0.75+(n%5)*8*0.95<<endl; } if(n%5==3) { cout<<i-1<<"套5本的"<<endl; cout<<"加2套4本"<<endl; cout<<"最低价格为:"<<(i-1)*8*5*0.75+2*4*8*0.8<<endl; } if(n%5==4) { cout<<i<<"套5本"<<endl; cout<<"加"<<n%5<<"本"<<endl; cout<<"最低价格为:"<<i*8*5*0.75 +(n%5)*8*0.8<<endl; } } }
时间: 2024-10-28 10:10:55