码迷,mamicode.com
首页 > 其他好文 > 详细

关于《哈利波特》书的购买方案

时间:2015-06-23 11:41:30      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

思路:

购买时只需按(x*5+y)(0<y<5),x套5本另外买y本(0<y<5)时价格最低。

代码:

#include <iostream>
using namespace std;

void main()
{
    int n;
    cout << "请输入要购买书的本数:" << endl; 
    cin >> n;

    int i;
    i = n/5;

    if (n < 5)
    {
        switch(n)
        {
        case 1:
            cout << "买1本书最低价格为8元"<< endl;
            break;
        case 2:
            cout << "买2本书最低价格为" << n*8*0.95 << ""<< endl;
            break;
        case 3:
            cout << "买3本书最低价格为" << n*8*0.9 << ""<< endl;
            break;
        case 4:
            cout << "买4本书最低价格为" << n*8*0.8 << ""<< endl;
        }
    }
    else{
        switch(n%5)
        {
        case 0:
            cout << "" << i << "套5本的" << endl;
            cout << "最低价格为:" << i*8*5*0.75<< endl;
            break;
        case 1:
            cout << "" << i << "套5本的" << endl;
            cout << "外加" << n%5 << "" << endl;
            cout << "最低价格为:" << i*8*5*0.75 + (n%5)*8<< endl;
            break;
        case 2:
            cout << "" << i << "套5本的" << endl;
            cout << "外加" << n%5 << "" << endl;
            cout << "最低价格为:" << i*8*5*0.75 + (n%5)*8*0.95 << endl;
            break;
        case 3:
            cout << "" << i-1 << "套5本的" << endl;
            cout << "外加2套4本" << endl;
            cout << "最低价格为:" << (i-1)*8*5*0.75 + 2*4*8*0.8 << endl;
            break;
        case 4:
            cout << "" << i << "套5本的" << endl;
            cout << "外加" << n%5 << "" << endl;
            cout << "最低价格为:" << i*8*5*0.75 + (n%5)*8*0.8 << endl;
        }
    }
}

技术分享

技术分享

 

关于《哈利波特》书的购买方案

标签:

原文地址:http://www.cnblogs.com/hongyedeboke/p/4594783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!