zoukankan      html  css  js  c++  java
  • 百鸡百钱

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            static void Main(string[] args)
            {
                ////单位给发了一张150远的购物卡,去买三中东西,洗发水15元,香皂2元,牙刷5元,求刚好花完150元,有多少种卖法,
                ////每种各买多少?
                ////设洗发水x 香皂z 牙刷y
               //for循环
                int a = 0;
                for (int x = 0; x <= 10; x++)//假设洗发水为x
                {
                    for (int y = 0; y <= 30; y++)//假设牙刷为y
                    {
                        for (int z = 0; z <= 75; z++)//假设香皂为z
                        {
                            if (15 * x + 2 * z + 5 * y == 150)//判断计算
                            {
                                a++;
                                Console.WriteLine("够买洗发水" + x + "瓶,香皂" + z + "块,牙刷" + y + "");
                            }
                        }
                    }
                }
                Console.WriteLine("共有" + a + "");
                Console.ReadLine();
    
                //百鸡百钱,公鸡2文钱一只,母鸡1文钱一只,小鸡半文钱一直。
                //共有100问钱,如何凑够100只鸡的情况下,刚好花完100文钱。
                int count = 0;
                for (int gong = 0; gong <= 50; gong++)
                {
                    for (int mu = 0; mu <= 100; mu++)
                    {
                        for (int xiao = 0; xiao <= 200; xiao++)
                        {
                            if (gong + mu + xiao == 100 && 2 * gong + 1 * mu + 0.5 * xiao == 100)
                            {
                                count++;
                                Console.WriteLine("够买公鸡" + gong + "只,母鸡" + mu + "只,小鸡" + xiao + "");
                            }
                        }
                    }
                }
                Console.WriteLine("共有" + count + "");
                Console.ReadLine();
    
    
                //for循环的变形得到while循环
                //初始条件拿到前面
                //循环的状态改变放在魂环体的最后一句
                //for变成while,渐远的的分号去掉,只留下循环体。
    
    
    
    
                ////纸张厚度0.07毫米
                ////折叠多少次能够到8848米
                int i = 7;
                int a = 0;
                while (i <= 884800000)
                {
                    i *= 2;
                    a++;
                }
                Console.WriteLine(a);
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    对象并不一定都是在堆上分配内存的
    Minor GC、Major GC和Full GC之间的区别
    JAVA内存分配与回收策略
    HotSpot虚拟机对象相关内容
    JAVA运行时数据区域
    Java 的强引用、弱引用、软引用、虚引用
    去哪儿网支付系统架构演进(下篇)
    去哪儿网支付系统架构演进(上)
    心智模式:如何改善我们的心智模式?
    心智模式:心智模式成熟的标志
  • 原文地址:https://www.cnblogs.com/zhangdemin/p/5472565.html
Copyright © 2011-2022 走看看