daba.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:1k
源码类别:
C#编程
开发平台:
Others
- using System ;
- public class M
- {
- //public static int[] store;
- //相当于设置了全局变量
- //这个全局变量sum是包含在M类中的
- public static int sum;
- public M()
- {
- int sum =0;
- // int[] store = {1,2,3,4,5,6,7,8,9,0};
- }
- //打印函数
- //符合要求的则把他打印出来
- public static void Output(int[] store2)
- {
- for(int i = 9; i>=0; --i)
- {
- Console.Write(" {0}",store2[i]);
- }
- Console.WriteLine();
- sum++;
- }
- //计算总数 返回sum值
- public static int sum2()
- {
- return sum;
- }
- public static void Cumput(int score, int num, int[] store2 )
- {
- //如果预期达到靶数小于0或者大于10环*剩下要打得次数
- //也就是说即便后面的都打十环也无法打够次数
- //则退出递归
- if(score < 0 || score > (num+1)*10 ) //次数num为0到9
- {
- return;
- }
- //如果满足条件 且达到最后一层
- if(num == 0)
- {
- store2[num] = score;
- Output( store2);
- return;
- }
- for(int i = 0; i <= 10; ++i)
- {
- store2[num] = i;
- Cumput(score - i, num - 1,store2);
- }
- //Console.Write(" {0}",store2[5]);
- }
- }
- public class myApp
- {
- public static void Main( )
- {
- int[] store;
- store = new int[10];
- int sum = 0;
- //int a=90;
- //int b=9;
- //Output();
- M.Cumput(90,9,store);
- sum = M.sum2();
- //M.Cumput2(a,b,store);
- //Console.Write(" {0}",store[3]);
- //cout<<"总数:"<<sum<<endl;
- Console.Write(" 总数: {0}",sum);
- Console.ReadLine();
- }
- }