[Huawei machine trial exercise questions] 35. Change the price, Huawei change
Question
Description:
We know that RMB 1, 2, 5, 10, 20, 50, and 100 are denominations. Now we will give you n (1 ≤ n ≤ 250) yuan, so that you can use the above denominations for calculation and the total number should not exceed 100. There are several types. For example, you can use four RMB 1, two RMB 1, and one RMB 2, or two RMB 2.
Question category:
Loop
Difficulty:
Elementary
Running time limit:
10Sec
Memory limit:
128MByte
Phase:
Pre-Employment exercises
Input:
There are multiple groups of input, one row in each group, and one integration n. The input ends with 0.
Output:
The output can be expressed in several ways.
Sample input:
140
Sample output:
13
Code
/* ------------------------------------- * Date: 2015-07-02 * Author: SJF0115 * Subject: Change * Source: huawei trial exercise questions ----------------------------------------- */# include <iostream> # include <vector> # include <string> # include <algorithm> # include <list> using namespace std; int money [] = {100,}; // n money [index] <= n <money [index + 1] int ChangeMoney (int n, int index) {if (n = 1 | n = 0 | index = 0) {return 1;} // if If (n <0 | index <0) {return 0;} // if return ChangeMoney (n-money [index], index) + ChangeMoney (n, index-1) ;}int main () {int n; // freopen ("C: \ Users \ Administrator \ Desktop \ c00000000.txt", "r ", stdin); int count = sizeof (money)/sizeof (money [0]); while (cin> n & n! = 0) {int index = 0; for (int I = count-1; I> = 0; -- I) {if (n> = money [I]) {index = I; break;} // if} // for cout <ChangeMoney (n, index) <endl ;}// while return 0 ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.