zjbonrace 2015-01-20 04:16 采纳率: 100%
浏览 1731
已采纳

link制作课程表,这个程序修改后还是有时会出现体育课在第一节,请问哪里错了

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 = { "体育课", "体育课", "美术课", "音乐课", "劳动课", "语文课", "数学课", "英语课" };
string[] xinqi = { "一", "二", "三", "四", "五" };
var result = Enumerable.Range(0, 5).Select(_ => Enumerable.Range(0, 6).Select(__ => "").ToArray()).ToArray();
while (!result.All(x => x.Contains("语文课") && x.Contains("数学课") && x.Contains("英语课") && x.Contains("自修课") && x[0] != "体育课"))
{
var rndseq = Enumerable.Range(0, 30).OrderBy(_ => Guid.NewGuid()).Zip(courses, (x, y) => new { x, y }).ToArray();
for (int i = 0; i < 5; i++)
{
int pos = 0;
string[] cs = { "语文课", "数学课", "英语课" };
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] = (pos++ < 3) ? cs[pos - 1] : "自修课";
}
}
}
result = result.Select((x, i) => new string[] { "星期" + xinqi[i] }.Concat(x.OrderBy(y => y == "自修课" ? 1 : 0).ThenBy(_ => Guid.NewGuid()).GroupBy(y => y).SelectMany(y => y)).ToArray()).ToArray();
for (int j = 0; j < 7; j++)
{
for (int i = 0; i < 5; i++)
{
Console.Write(result[i][j] + "\t");
}
Console.WriteLine();
}
}
}
}

  • 写回答

2条回答 默认 最新

  • threenewbee 2015-01-20 04:23
    关注
     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 = { "体育课", "体育课", "美术课", "音乐课", "劳动课", "语文课", "数学课", "英语课" };
                string[] xinqi = { "一", "二", "三", "四", "五" };
                var result = Enumerable.Range(0, 5).Select(_ => Enumerable.Range(0, 6).Select(__ => "").ToArray()).ToArray();
                while (!result.All(x => x.Contains("语文课") && x.Contains("数学课") && x.Contains("英语课") && x.Contains("自修课") && x[1] != "体育课"))
                {
                    var rndseq = Enumerable.Range(0, 30).OrderBy(_ => Guid.NewGuid()).Zip(courses, (x, y) => new { x, y }).ToArray();
                    for (int i = 0; i < 5; i++)
                    {
                        int pos = 0;
                        string[] cs = { "语文课", "数学课", "英语课" };
                        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] = (pos++ < 3) ? cs[pos - 1] : "自修课";
                        }
                    }
                    result = result.Select((x, i) => new string[] { "星期" + xinqi[i] }.Concat(x.OrderBy(y => y == "自修课" ? 1 : 0).ThenBy(_ => Guid.NewGuid()).GroupBy(y => y).SelectMany(y => y)).ToArray()).ToArray();
                }
                for (int j = 0; j < 7; j++)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        Console.Write(result[i][j] + "\t");
                    }
                    Console.WriteLine();
                }
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记