1using System;
 2
 3namespace test16
 4{
 5    /// <summary>
 6    /// 指定数量,指定总额,求公鸡/母鸡/小鸡各多少
 7    /// </summary>

 8    class Class1
 9    {
10        /// <summary>
11        /// 应用程序的主入口点。
12        /// </summary>

13        [STAThread]
14        static void Main(string[] args)
15        {
16            Buy(9,3);
17        }

18        public static void Buy(int money,int count)
19        {
20            int cock=-1,hen,chick;
21            while(cock<=count)
22            {
23                cock++;
24                hen=-1;
25                while(hen<=count)
26                {
27                    hen++;
28                    chick = count-cock-hen;
29                    if(cock*5+hen*3+chick==money)
30                    {
31                        Console.WriteLine("cock={0},hen={1},chick={2}",cock,hen,chick);
32                        continue;
33                    }

34                }

35            }

36        }

37    }

38}

39

只有注册用户登录后才能发表评论。

posts - 46, comments - 16, trackbacks - 0, articles - 7

Copyright © 火山工作室