首页 > 解决方案 > 算法比较 2 个列表并找到错误最少的方法

问题描述

我在制作算法来计算两个列表之间的差异时遇到了一些麻烦。

第一个列表是预期列表,这意味着,如果一切按计划进行,这就是它的外观。

第二个列表是它的实际情况列表。

我需要比较这些以列出并找出是否缺少检查点或者是否存在错误说明,这意味着已经记录了不应该记录的检查点。检查点的顺序很重要,它必须与预期的顺序相同。

我的问题是如何比较这两个列表并制作它并找到最少的错误,并标记这些错误。

目前我已经做了 3 节课。

预期类:

public class IdealRouteCheckpoint : ICheckpoint
{
    public IdealRouteCheckpoint(string checkpointValue, int minTime = 0, int maxTime = 0, bool defective = false, bool optional = false)
    {
        CheckpointValue = checkpointValue;
        Defective = defective;
        Optional = optional;
        MinTime = minTime;
        MaxTime = maxTime;
    }

    public string CheckpointValue { get; set; }

    //Used for when a Checkpoint this missing for when it placed wrong
    public bool Defective { get; set; } 
    //Used for when you do somehitng and know that people risk taking it
    public bool Optional { get; set; }

    //Used for OTK and HTK
    public int MinTime { get; set; }
    public int MaxTime { get; set; }
}

带有检查点的课程实际上是如何去的。

public class NotedCheckPoint : ICheckpoint
{
    public NotedCheckPoint(string checkpointValue)
    {
        CheckpointValue = checkpointValue;
    }

    public string CheckpointValue { get; set; }


}

然后我正在考虑制作一个应该有结果和错误标记的第三类,所以我最终可以将结果打印到 PDF 中。那个类看起来像这样。

public class ResultCheckpoint : ICheckpoint
{
    public ResultCheckpoint(string checkpointValue, bool missing = false, bool errorNote = false, int early = 0, int late = 0)
    {
        CheckpointValue = checkpointValue;
        Missing = missing;
        ErrorNote = errorNote;
        Early = early;
        Late = late;
    }

    public string CheckpointValue { get; set; }

    //MK when a checkpoint is missing on the controlCard
    public bool Missing { get; set; }
    //FN when there is a checkpoint too much on the controlCard
    public bool ErrorNote { get; set; }

    //When teams are too early to a HTK or OTK
    public int Early { get; set; }
    //When teams are too late to a HTK or OTK
    public int Late { get; set; }
}

我已经描绘了我想要实现的目标,但我认为我需要解释一些事情。

左列是预期的,没有任何内容的单元格是为错误注释腾出空间。

结果列是实际记录的内容。没有任何东西的单元格是为缺少的检查点腾出空间。

每个错误说明和缺失的检查点都需要 25 分。

最后一件事是有时间,但我想当我找到解决问题的方法时,我可以处理那部分。

这是一张图片来说明我的意思

标签: c#algorithm

解决方案


推荐阅读