找零钱

#include <stdio.h>

int main() {
    int oneYuan,towYuan, fiveYuan,count=0;
    int sum_money;
    scanf("%d",&sum_money);
    int  mostOne = sum_money - 7,mostTow = (sum_money - 6) / 2, mostFive = (sum_money - 3) / 5;  //缩小范围
    for(fiveYuan = mostFive; fiveYuan>0; fiveYuan--)
    {
        for(towYuan = mostTow; towYuan > 0; towYuan--)
        {
            for(oneYuan = mostOne; oneYuan > 0; oneYuan--)
            {
                if(oneYuan + 2 * towYuan + 5 * fiveYuan == sum_money)
                {
                    printf("%d %d %d\n", fiveYuan, towYuan, oneYuan);
                    count++;
                }
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

任务描述

本关任务:将一面额为10元倍数的整钱(<=100元)换成1元、2元和5元的零钱组合(每种面值都要有)。输入要换的面额(如10元),输出所有可能的换法及其数量。

请注意,由于结果集的种类比较多,为了匹配和通过测试集,要求你的输出要依次按5元、2元、1元的数量从多到少的组合

posted @ 2020-04-04 19:01  ethon-wang  阅读(454)  评论(0编辑  收藏  举报