百鸡百钱

            //百鸡百钱 ,公鸡2文钱一只,母鸡1文钱一只,小鸡半文钱一只
            //共有100文钱,如何在凑够100只鸡的情况下刚好花完100文钱
            int count = 0; int bian = 0;
            for (int gong = 0; gong <= 50;gong++ )
            {
                for (int mu = 0; mu <= 100;mu++ )
                {
                    for (int xiao = 0; xiao <= 200;xiao++ )
                    {
                        bian++;
                        if(gong+mu+xiao==100&&gong*2+mu+xiao*0.5==100)
                        {
                            count++;
                            Console.WriteLine(""+count+"种情况:公鸡:"+gong+"只,母鸡:"+mu+"只,小鸡:"+xiao +"");
                        }
                    }
                }
            }
            Console.WriteLine("共有"+count+"种买法。");
            Console.WriteLine(bian);
            Console.ReadLine();

 

posted @ 2016-05-04 21:51  枫炎  阅读(262)  评论(0编辑  收藏  举报