#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;
}
|