zoukankan      html  css  js  c++  java
  • 购书优惠问题

    一,问题描述

      
      书店针对《哈利波特》系列书籍进行促销活动,一共5卷,用编号0、1、2、3、4表示,单独一卷售价8元, 具体折扣如下所示:

                                   本数                  折扣

                                       2                       5%

                                       3                       10%

                                       4                       20%

                                       5                       25%

      根据购买的卷数以及本数,会对应不同折扣规则情况。单数一本书只会对应一个折扣规则,例如购买了两本卷1,一本卷2,则可以享受5%的折扣,另外一本卷一则不享受优惠。设计算法能够计算出读者购买一批书的最低价格。

    二、设计思想

    易知购买五本时的最大优惠,大于五本时可以转化为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;
     
    }

    四、实现截图

    五、个人总结

    注意总结规律。

  • 相关阅读:
    Script:List NLS Parameters and Timezone
    Script:List Buffer Cache Details
    Know about RAC Clusterware Process OPROCD
    RAC Deadlock For Example
    Know more about redo log buffer and latches
    如何设计分区索引
    SCN may jump in a distributed transaction with dblink
    Script to Collect Log File Sync Diagnostic Information (lfsdiag.sql)
    Oracle学习笔记:10046 SQL tracle event
    Oracle学习笔记:创建physical standby
  • 原文地址:https://www.cnblogs.com/a1264393659/p/5558412.html
Copyright © 2011-2022 走看看