穷举 百鸡百钱

 static void Main(string[] args)
        {
            while (true)
            {
              
                int n = 0;
                for (int g = 1; g*2 <=100; g++)
                {
                    for (int m = 1; m*1 <=100; m++)
                    {
                        for (int x = 1; x*0.5 <=100; x++)
                        {
                            if(g*2+m*1+x*0.5==100&&g+m+x==100)
                            {
                                Console.WriteLine(g+"只公鸡"+m+"只母鸡"+x+"只小鸡");
                               n++;
                            }
                        }
                    }
                }
                Console.WriteLine("共有"+n+"种可能性");
                Console.ReadLine();
            }
        }

posted @ 2015-04-02 19:05  XCml  阅读(123)  评论(0编辑  收藏  举报