zoukankan      html  css  js  c++  java
  • Hua Wei 机试题目二

    题目描述:
    假设1元,5元,10元,50元,100元的人民币若干,实现一个能找到最少张数累计达到一个指定金额方法。如:67元,可分为67个1元钱。也可分为6个10元7个1元,其中最少人民币分法为一张50元,一张10元,一张5元,两张1元,五张不同金额的拆分方法为最最少张数拆分法。

    要求实现函数:
    void CalLeastChange(long lInputValue, int *iOutputRlt)
    【输入】 lInputValue: 输入整数金额
    【输出】 lOutputRlt: 输出计算结果
    【注意】仅考虑整数金额拆分方法
    示例
    输入:“67”
    输出:“5”

    #include<iostream>
    using namespace std;
    
    void CalLeastChange(long lInputValue, int *iOutputRlt)
    {
        int highNum=lInputValue/(10*10);
        int lowerNum=lInputValue-(lInputValue/10)*10;
        int curNum=(lInputValue/10)%10;
    
        int count=highNum;
        if(curNum>=5)
        {
            count++;
            curNum-=5;
        }
        count=count+curNum;
    
        if(lowerNum>=5)
        {
            count++;
            lowerNum-=5;
        }
        count=count+lowerNum;
    
        *iOutputRlt=count;
    
        cout<<*iOutputRlt<<endl;
    
    }
    
    int main()
    {
        int lInputValue=1238;
        int lInputValue1=67;
        int iOutputRlt[]={0};
        CalLeastChange(lInputValue,iOutputRlt);
        CalLeastChange(lInputValue1,iOutputRlt);
        return 0;
    }
  • 相关阅读:
    2-括号配对问题
    14-会场安排问题
    106-背包问题
    12-喷水装置
    HDU-5170
    HDU-1002
    贪吃蛇
    frame与bounds的区别
    MAC下Android的Eclipse开发环境的搭建
    有些人脸上太多的笑是因为他们心中有太多的泪
  • 原文地址:https://www.cnblogs.com/yvictoryr/p/3826741.html
Copyright © 2011-2022 走看看