咳..第二题发现个问题.出栈后,,stack的值是在减小的..当i跟stack.count值相等时,就会跳出循环,所以得不到想要的结果..

解决方案 »

  1.   

    第一题正确答案:
    int count = 0;
                for (int one = 0; one < 101;one++ )
                {
                    for (int two = 0; two < 51;two++ )
                    {
                        for (int five = 0; five < 21;five++ )
                        {
                            if (one*1+two*2+five*5==100)
                            {
                                Console.WriteLine("{0} one,{1} two,{2} five", one, two, five);
                                count++;
                            }
                        }
                    }
                }
                Console.WriteLine(count.ToString());
                Console.ReadKey();
      

  2.   

    上楼的兄弟,先不说你的答案是不是最标准的,但至少在程序的写法上就有一个很大的失误,看看这样写效果会怎么样........int count = 0;
                for (int five = 0; five < 21; five++)
                {
                    for (int two = 0; two < 51; two++)
                    {
                        for (int one = 0; one < 101; one++)
                        {
                            if (one * 1 + two * 2 + five * 5 == 100)
                            {
                                Console.WriteLine("{0} five,{1} two,{2} one", five, two, one);
                                count++;
                            }
                        }
                    }
                }
                Console.WriteLine(count.ToString());
                Console.ReadKey();
      

  3.   

    在上面的控制台里面看不到全部的。可以写到一个文件里面去。
    代码如下:string path = @"c:\MyTest.txt";
                if (!File.Exists(path))
                {
                    // Create a file to write to.
                    string[] createText = { "Hello", "And", "Welcome" };
                    File.WriteAllLines(path, createText);
                }            int count = 0;
                for (int one = 0; one < 101;one++ )
                {
                    for (int two = 0; two < 51;two++ )
                    {
                        for (int five = 0; five < 21;five++ )
                        {
                            if (one*1+two*2+five*5==100)
                            {
                                Console.Write("{0} one,{1} two,{2} five", one, two, five);
                                string appendText = one.ToString()+"one, "+two.ToString()+"two, "+five.ToString()+"five "+ Environment.NewLine;
                                File.AppendAllText(path, appendText);
                                count++;
                            }
                        }
                    }
                }
                Console.WriteLine(count.ToString());
                File.AppendAllText(path, count.ToString());
                Console.ReadKey();
      

  4.   

    楼上的兄弟,我这个答案怎么样............
    int count = 0;
                //先求5分的数量
                for (int i = 0; i < 101; i = i + 5)
                {
                    //之后求2分可以出现的次数
                    count += (i / 2 + 1);
                }
                Console.WriteLine(count.ToString());