逐至 2021-06-07 10:48 采纳率: 100%
浏览 55
已采纳

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

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

提取码: 4vmh 

  • 写回答

2条回答 默认 最新

  • soar3033 2021-06-07 12:48
    关注
    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;
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示