已知有面值为1元,2元,5元,10元,20元,50元,100元的货币若干(可认为无穷多),需支付价格为x的物品,并需要恰好支付,即没有找零产生。
求,至少需要几张货币才能完成支付。
如,若支付价格为12元的物品,最少需要一张10元和一张2元,即两张货币就可完成支付。
输入包含多组测试数据,每组仅包含一个整数p(1<=p<=100000000),为需支付的物品价格。
对于每组输入数据,输出仅一个整数,代表最少需要的货币张数。
10 11 13
1 2 3
#include <stdio.h>
int main()
{
int x,a,b,c,d,e,f,g;
while(scanf("%d",&x)!=EOF)
{
a=b=c=d=e=f=g=0;
a=x/100;
x-=a*100;
b=x/50;
x-=b*50;
c=x/20;
x-=c*20;
d=x/10;
x-=d*10;
e=x/5;
x-=e*5;
f=x/2;
x-=f*2;
g=x/1;
x-=g*1;
printf("%d\n",a+b+c+d+e+f+g);
}
return 0;
}
/**************************************************************
Problem: 1549
User: vhreal
Language: C
Result: Accepted
Time:10 ms
Memory:912 kb
****************************************************************/原文地址:http://blog.csdn.net/wtyvhreal/article/details/42077933