Statistics of change method for recursive exercises (c + +)

Source: Internet
Author: User

/********************************************************************************* Copyright (C), 1988-1999, Drvivermonkey.   Co., Ltd. File name:Author:Driver Monkey version:mail:[email protected] qq:196568501 date:2014.04.02 Description : The change method of the recursive practice statistics (c + +) *********************************************************************************/#include <iostream> #include <sstream> #include <fstream> #include <iostream> #include <iomanip># Include <string> #include <memory.h> #include <thread> #include <stdlib.h>/* Labs */#include &L    t;math.h>using namespace std;typedef struct{int value; int flag;}    Valut_t;typedef struct{valut_t value_50;    valut_t value_25;    valut_t value_10;    valut_t value_5; valut_t Value_1;} all_value_t;static int fuction (int total_money, all_value_t value), static int Is_only_50_change (all_value_t& value ), static int is_only_25_change (all_value_t& value), static int iS_only_10_change (all_value_t& value); static int Is_only_5_change (all_value_t& value); static int is_only_1_    Change (all_value_t& value); int main () {all_value_t value = {{50,1},{25,1},{10,1},{5,1},{1,1}};    cout<< "fuction =" <<fuction (100,value) <<endl; return 0;}    static int fuction (int total_money, all_value_t value) {if (Total_money = = 0) {return 1;    }else if (Total_money < 0) {return 0;        } if (Value.value_50.flag = = True) {if (Is_only_50_change (value)) {return 1;        } all_value_t temp_value = value;        Temp_value.value_50.flag = false;    Return fuction (Total_money, Temp_value) + fuction (total_money-50, value);        } else if (value.value_25.flag== true) {if (Is_only_25_change (value)) {return 1;        } all_value_t temp_value = value;        Temp_value.value_25.flag = false; Return fuction (Total_money, Temp_value) + fuction (total_money-25, value);        }else if (Value.value_10.flag = = True) {if (Is_only_10_change (value)) {return 1;        } all_value_t temp_value = value;        Temp_value.value_10.flag = false;       Return fuction (Total_money, Temp_value) + fuction (total_money-10, value);        }else if (Value.value_5.flag = = True) {if (Is_only_5_change (value)) {return 1;        } all_value_t temp_value = value;        Temp_value.value_5.flag = false;        Return fuction (Total_money, Temp_value) + fuction (total_money-5, value);        }if (Value.value_1.flag = = True) {if (Is_only_1_change (value)) {return 1;        } all_value_t temp_value = value;        Temp_value.value_1.flag = false;        Return fuction (Total_money, Temp_value) + fuction (total_money-1, value);    }else {return 0;   }}static int Is_only_50_change (all_value_t& value) {if (Value.value_25.flag  & Value.value_10.flag & Value.value_5.flag & Value.value_1.flag) = = False) {return true;    }else {return false; }}static int Is_only_25_change (all_value_t& value) {if ((Value.value_50.flag = = False) && (value.value_1 0.flag = = False) && (Value.value_5.flag = = False) && (Value.value_1.flag = = False)) && (Valu    E.value_25.flag = = True) {return true;    }else {return false; }}static int Is_only_10_change (all_value_t& value) {if ((Value.value_25.flag = = False) && (Value.valu E_50.flag = = False) && (Value.value_5.flag = = False) && (Value.value_1.flag = = False)) &    & (Value.value_10.flag = True) {return true;    }else {return false; }}static int Is_only_5_change (all_value_t& value) {if ((Value.value_25.flag = = False) && (value.value_10. Flag = = False) && (value.value_50.flag = = False) && (Value.value_1.flag = = False)) && (Value.value_5.flag = = True)) {Retur    n true;    }else {return false; }}static int Is_only_1_change (all_value_t& value) {if ((Value.value_25.flag = = False) && (value.value_10.f lag = False) && (Value.value_5.flag = = False) && (Value.value_50.flag = = False)) && (Val    Ue.value_1.flag = = True) {return true;    }else {return false; }}

Statistics of change method for recursive exercises (c + +)

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.