link生成随机课程表,要求每天6节课

link生成随机课程表,要求每天6节课,每天都有语文数学英语,总共各7节,体育课2节,美术课1节,音乐课1节,劳动课1节,社会课1节,自然课1节,思想品德课1节,剩下都是自修课。

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] courses = { "体育课", "体育课", "美术课", "音乐课", "劳动课", "语文课", "语文课", "语文课", "语文课", "语文课", "语文课", "语文课", 
                                   "数学课", "数学课", "数学课", "数学课", "数学课", "数学课", "数学课", "英语课", "英语课", "英语课", "英语课", "英语课",
                               "英语课", "英语课"};
            var result = Enumerable.Range(0, 5).Select(_ => Enumerable.Range(0, 6).Select(__ => "").ToArray()).ToArray();
            var rndseq = Enumerable.Range(0, 30).OrderBy(_ => Guid.NewGuid()).Zip(courses, (x, y) => new { x, y }).ToArray();
            while (true && !result.All(x => x.Contains("语文课") && x.Contains("数学课") && x.Contains("英语课")))
            {
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (rndseq.Any(x => x.x == i * 6 + j))
                            result[i][j] = rndseq.First(x => x.x == i * 6 + j).y;
                        else
                            result[i][j] = "自修课";
                    }
                }
            }
            for (int j = 0; j < 6; j++)
            {
                for (int i = 0; i < 5; i++)
                {
                    Console.Write(result[i][j] + "\t");
                }
                Console.WriteLine();
            }
        }
    }
}

这个简单,你稍微等下,我写一个给你。