zoukankan      html  css  js  c++  java
  • for练习--凑法

    static void Main14购物卡(string[] args)
            {
                //小明单位发了50元的购物卡,他到超市买洗化用品,一是牙刷(5元),二是香皂(2元),三是牙膏(10元)怎么可以正好把五十元花完。
    
                for (int i = 0; i <= 10; i++)
                {
    
                    for (int x = 0; x <= 25; x++)
                    {
                        for (int g = 0; g <= 5; g++)
                        {
                            if (i * 5 + x * 2 + g * 5 == 50)
                            {
                                Console.WriteLine("牙刷	" + i + "个,香皂	" + x + "个,牙膏	" + g + "");
                            }
                        }
                    }
                }
            }
     static void Main15白文白鸡(string[] args)
            {
                //公鸡两文/只,母鸡一文/只,小鸡半文/只,花100文钱,买100只鸡,该如何购买?
                Console.WriteLine("买法有:");
                int n = 0;
                for (int a = 0; a <= 50; a++)
                {
                    for (int b = 0; b <= 100; b++)
                    {
                        for (int c = 0; c <= 200; c++)
                        {
                            if (a + b + c == 100 && a * 2 + b * 1 + c * 0.5 == 100)
                            {
                                n++;
                                Console.WriteLine("公鸡" + a + "母鸡" + b + "小鸡" + c);
                            }
                        }
                    }
                }
                Console.WriteLine("共有{0}种买法", n);
            }
     static void Main16白马百担(string[] args)
            {
                //白马百担:大马驮2担粮食,中马驮1担粮食,两头小马驮1担粮食,要用100匹马,驮100担粮食,该如何调配?
                int n = 0;
                for (int a = 0; a <= 50; a++)
                {
                    for (int b = 0; b <= 100; b++)
                    {
                        for (int c = 0; c <= 200; c++)
                        {
                            if (a + b + c == 100 && a * 2 + b * 1 + c * 0.5 == 100)
                            {
                                n++;
                                Console.WriteLine("大马{0}	中马{1}	小马{2}", a, b, c);
                            }
                        }
                    }
                }
                Console.WriteLine("共有{0}种驮法", n);
    
            }
    static void Main17凑钱(string[] args)
            {
                //有1块、2块、5块的钱若干,凑出20块,有几种凑法?
    
                int n = 0;
                for (int a = 0; a <= 20; a++)
                {
                    for (int b = 0; b <= 10; b++)
                    {
                        for (int c = 0; c <= 4; c++)
                        {
                            if (a * 1 + b * 2 + c * 5 == 20)
                            {
                                n++;
                                Console.WriteLine("一块的{0},2块的{1},五块的{2}", a, b, c);
                            }
                        }
                    }
                }
                Console.WriteLine("共有{0}种凑法", n);
            }
  • 相关阅读:
    Python学习——模块的基本知识
    Python学习-软件目录结构规范
    路径追踪的理论与实现:复合重要性采样
    路径追踪的理论与实现:渲染方程
    记一个C++随机数导致的bug
    Gamma矫正的原理和实现
    聊一聊Python的sort函数
    BVH树的构建与遍历
    Cocos动画系统
    Cocos事件分发系统
  • 原文地址:https://www.cnblogs.com/SJP666/p/4646596.html
Copyright © 2011-2022 走看看