如何C++编程解决用最少的张数人民币凑成所需钱数?

来源:百度知道 编辑:UC知道 时间:2024/06/04 22:37:42
编程序,输入正整数m代表钱数,求方案用最少的人民币(面值为100,50,20,10,5,2,1)凑成这个钱数,输出每种面值人民币各需多少张.要求用类,对象,函数.

//有浓重的C风格,习惯,不好意思
// zd_60.cpp : Defines the entry point for the console application.
//

#include <string.h>
#include <stdio.h>
#include <conio.h>

class money
{
private:
int total;
int result[7];
public:
money(int total);
void num();
int *getresult();
};

money::money(int a)
{
total=a;
for(int i=0;i<7;i++)
result[i]=0;
}

void money::num()
{
if(total>=100)
{
total-=100;
result[0]++;
this->num();
}
else if(total>=50)
{
total-=50;
result[1]++;
this->num();
}
else if(total>=20)
{
total-=20;
result[2]++;
this->num();
}
else if(total>=10)
{
total-=10;
result[3]++;
this->num();
}
else if(total>=5)
{
total-=5;
result[4]+