9-degree OJ-question 1549: currency problem, 9-degree oj1549 currency
-
Description:
-
It is known that the nominal value is 1 yuan, 2 yuan, 5 yuan, 10 yuan, 20 yuan, 50 yuan, a number of currencies of 100 yuan (can be considered infinite ), you need to pay for an item whose price is x, and pay exactly for it.
Please, at least a few currencies are required to complete the payment.
For example, if the payment price is 12 yuan, you need at least 10 yuan and 2 yuan, that is, you can complete the payment in two currencies.
-
Input:
-
Input contains multiple groups of test data, each group contains only one integer p (1 <= p <= 100000000), for the price of the item to be paid.
-
Output:
-
For each group of input data, only one integer is output, representing the minimum number of required currencies.
-
Sample input:
-
101113
-
Sample output:
-
123
-
Source:
-
2014 Wang Dao Forum study life trial exercise (2)
#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****************************************************************/