码迷,mamicode.com
首页 > 其他好文 > 详细

穷举 百文百鸡

时间:2015-04-13 20:50:46      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

           static void Main(string[] args)                                            //记住格式
        {
            int n = 0;
            for (int x = 1; x * 2 <= 100; x++)
            {
                for (int y = 1; y * 1 <= 100; y++)
                {
                    for (int z = 1; z * 0.5 <= 100; z++)
                    {
                        if (x*2+y*1+z*0.5==100&&x+y+z==100)
                        {
                            System.Threading.Thread.Sleep(300);
                            Console.WriteLine(x+"只公鸡   "+y+"只母鸡    "+z+"只小鸡    "+"一共"+(x+y+z)+"只鸡");
                            n++;
                        }
                    }
                }
            }
           
            Console.Write("共有"+n+"种可能性");
            Console.ReadLine();
        }

穷举 百文百鸡

标签:

原文地址:http://www.cnblogs.com/Mr-xue/p/4423138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!