贪心算法 找钱问题

#include <iostream>
#include<algorithm>
using namespace std;
const int N=7;
int Count[N]={1,3,2,0,1,2,3};
int coin[N]={1,2,5,10,20,50,100};
int backMoney(int money){
  int number=0;
for(int i=N-1;i>=0;i--){

    int c=min(money/coin[i],Count[i]);
    number+=c;
    money-=c*coin[i];
}
if(money>0){
    number=-1;
}

return number;
}
int main()
{
    int money;
    cout<<"请输入多少钱"<<endl;
    cin>>money;
    int number=backMoney(money);
    if(number!=-1){
        cout<<number;

    }else{
       cout<<"换不开";
       }
    return 0;
}

    原文作者:贪心算法
    原文地址: https://blog.csdn.net/qq_39147516/article/details/78419157
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞