金钱划分

题目描述:
假设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 <stdio.h>

void main()
{
	int base[5] = {100,50,10,5,1};
	int money;
	int i;
	int result = 0;

	scanf_s("%d",&money);
	for (i = 0; i < 5; i++)
	{
		result += money / base[i];
		money = money % base[i];
	}

	printf("%d", result);
}
posted @ 2014-07-18 22:01  Andy Cheung  阅读(452)  评论(0编辑  收藏  举报