百钱买百鸡问题

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("用百元钱买百只鸡,公鸡每只5元,母鸡每只3元,小鸡1元3只~那么它们各是几只?");
            int max = 100;
            for (int a = 0; a <= max / 5; a++)
                for (int b = 0; b <= max / 3; b++)
                    for (int c = 0; c <= max * 3; c++)
                        if ((a + b + c == 100) && (a * 5 + b * 3 + c / 3.0 == 100.0))
                            Console.WriteLine("公鸡:{0}\t母鸡:{1}\t小鸡:{2}", a.ToString().PadLeft(2, '0'), b.ToString().PadLeft(2, '0'), c.ToString().PadLeft(2, '0'));
            Console.WriteLine("完成");
            Console.ReadKey();
        }
    }
}

 

posted @ 2013-04-25 17:40  ha666  阅读(248)  评论(0编辑  收藏  举报
ha666@ha666.com