[Huawei machine trial exercise questions] 35. Change the price, Huawei change

Source: Internet
Author: User

[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.