c#另一道编程题,进链接或扫描看文本,会的留下代码带注释,感谢

链接: https://pan.baidu.com/s/19ci2sXZTjurqNzSlzbY3Sw

提取码: 4vmh 

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

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Test t = new Test();
                t.test();
            }
        }
    }

    class Test
    {
        int types;
        int[] curs,curss;
        int count;
        List<int[]> results;
        public void test()
        {
            
            types=int.Parse(Console.ReadLine());
            curs =new int[types];
            curss = new int[types];
            results = new List<int[]>();
            string[] tmp= Console.ReadLine().Split(' ');
            for (int i = 0; i < types; i++)
            {
                curs[i] = int.Parse(tmp[i]);
            }
            count = int.Parse(Console.ReadLine());
            cal(0, 0);
            
            for (int i = 0; i < results.Count; i++)
            {
                string ss = "";
                for (int j = 0; j < results[i].Length; j++)
                {
                    for (int k = 0; k < results[i][j]; k++)
                    {
                        ss += curs[j];
                        ss += " ";
                    }
                    
                }
                Console.WriteLine(ss);
                //ss += "\n"; 
            }
            //Console.WriteLine(ss);
        }

        void cal(int b,int sum)
        {
            for (int i = (count-sum)/curs[b]; i >=0; i--)
            {
                curss[b] = i;
                int tmp = sum + i * curs[b];
                if (tmp == count)
                {
                    int[] cursst = new int[types];
                    for (int j = 0; j < types; j++)
                    {
                        cursst[j] = curss[j];
                    }
                    results.Add(cursst);
                }
                else
                {
                    if (b+1<types && tmp<count)
                    {
                        cal(b + 1, tmp);
                    }
                }
            }
            curss[b] = 0;
        }
    }
}

 

兄弟,在最后还是有点小问题,可以看下

输入

3

10 4 1

12

输出

10 1 1 

4 4 4 

4 4 1 1 1 1 

4 1 1 1 1 1 1 1 1 

1 1 1 1 1 1 1 1 1 1 1 1 

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 's')

   at System.Int32.Parse(String s)

   at ConsoleApp9.Test.test() in /home/adam/Desktop/student/paying.cs:line 30

   at ConsoleApp9.Program.Main(String[] args) in /home/adam/Desktop/student/paying.cs:line 16