分析和比较2个列表

时间:2016-10-12 13:25:49

标签: c# compare

我知道这听起来像是要求给我一把勺子,但我真的很模糊,并坚持制定几个逻辑,但仍然无法找到真正的交易。

我目前的系统目标是分析学生的成绩和考试成绩,以评估哪所大学专业适合他。

我已经完成了几乎所有系统的功能,除了这个系统的等式。

假设

I  = Grades Result
II = Examination Result

A = Major A
B = Major B
C = Major C

因此表格看起来像

   | A  |  B  |  C  |
---------------------
I  |    |     |     |
---------------------
II |    |     |     |

我需要制定一个结果,我可以评估几种可能的情况,例如:

   |  A  |  B  |  C  |
---------------------
I  |  1  |  2  |  3  |
---------------------
II |  1  |  3  |  2  |
表格中的

Major A1I上的排名均为II。因此,如果没有进一步的公式,学生最好选择Major A

和,在:

   |  A  |  B  |  C  |
---------------------
I  |  1  |  2  |  3  |
---------------------
II |  3  |  2  |  1  |

Major B2I上的排名均为II。因此,就像学生在III获得稳定结果的第一个示例一样,学生最好选择Major B

这里:

   |  A  |  B  |  C  |
---------------------
I  |  3  |  2  |  1  |
---------------------
II |  3  |  2  |  1  |

所有三个MajorsIII都有稳定的结果。但是,就排名而言,Major C的帖子最高,因此学生不会选择Major C

这对我来说是最棘手的部分:

   |  A  |  B  |  C  |
---------------------
I  |  1  |  2  |  3  |
---------------------
II |  2  |  1  |  3  |

Major C是唯一一个获得稳定结果的人。但鉴于它的帖子是3Major C不在等式中。因此,将进行计算。其中:

I =  60%
II = 40%

so 

Major A will be ((0.6 x 1) + (0.4 x 2)) = 1.4
Major B will be ((0.6 x 2) + (0.4 x 1)) = 1.6

因此,在等式中给出Major A的排名结果高于Major B。因此,学生将获得Major A作为专业的首选

我真的真的很难想到将方程式和想法转化为代码的方法,我将使用两个List<>。一个用于I,另一个用于II

所以,如果有人真的真的能在这里接我,我会非常感激。我已经没想到了这个。谢谢

我写了下面的代码,我知道它可能是丑陋的。

List<Ranking> Rank = new List<Ranking>();

// if all results are distinct to each other OR if all results are equal
if(
    (ExamResult[0].MajorResult != GradeResult[0].MajorResult && ExamResult[1].MajorResult != GradeResult[1].MajorResult && ExamResult[2].MajorResult != GradeResult[2].MajorResult)
  ||
    (ExamResult[0].MajorResult == GradeResult[0].MajorResult && ExamResult[1].MajorResult == GradeResult[1].MajorResult && ExamResult[2].MajorResult == GradeResult[2].MajorResult)
  )
{
    Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 1).Select(x => x.MajorDescription).Single(), Value = ExamResult.Where(x => x.MajorID == 1).Select(x => x.MajorResult).Single() + GradeResult.Where(x => x.MajorID == 1).Select(x => x.MajorResult).Single() });
    Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 2).Select(x => x.MajorDescription).Single(), Value = ExamResult.Where(x => x.MajorID == 2).Select(x => x.MajorResult).Single() + GradeResult.Where(x => x.MajorID == 2).Select(x => x.MajorResult).Single() });
    Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 3).Select(x => x.MajorDescription).Single(), Value = ExamResult.Where(x => x.MajorID == 3).Select(x => x.MajorResult).Single() + GradeResult.Where(x => x.MajorID == 3).Select(x => x.MajorResult).Single() });
}

// if one of the three is equal
if(ExamResult[0].MajorResult == GradeResult[0].MajorResult || ExamResult[1].MajorResult == GradeResult[1].MajorResult || ExamResult[2].MajorResult == GradeResult[2].MajorResult)
{
    var LowestRank1 = ExamResult.OrderBy(x => x.MajorResult).Last();
    var LowestRank2 = GradeResult.OrderBy(x => x.MajorResult).Last();

    var HighestRank1 = ExamResult.OrderBy(x => x.MajorResult).First();
    var HighestRank2 = GradeResult.OrderBy(x => x.MajorResult).First();

    if((ExamResult[0].MajorResult == LowestRank1.MajorResult) && (GradeResult[0].MajorResult == LowestRank2.MajorResult))
    {
        Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 2).Select(x => x.MajorDescription).Single(), Value = (ExamResult.Where(x => x.MajorID == 2).Select(x => x.MajorResult).Single() * 0.4) + (GradeResult.Where(x => x.MajorID == 2).Select(x => x.MajorResult).Single() * 0.6) });
        Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 3).Select(x => x.MajorDescription).Single(), Value = (ExamResult.Where(x => x.MajorID == 3).Select(x => x.MajorResult).Single() * 0.4) + (GradeResult.Where(x => x.MajorID == 3).Select(x => x.MajorResult).Single() * 0.6) });
    }

    if((ExamResult[1].MajorResult == LowestRank1.MajorResult) && (GradeResult[1].MajorResult == LowestRank2.MajorResult))
    {
        Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 1).Select(x => x.MajorDescription).Single(), Value = (ExamResult.Where(x => x.MajorID == 1).Select(x => x.MajorResult).Single() * 0.4) + (GradeResult.Where(x => x.MajorID == 1).Select(x => x.MajorResult).Single() * 0.6) });
        Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 3).Select(x => x.MajorDescription).Single(), Value = (ExamResult.Where(x => x.MajorID == 3).Select(x => x.MajorResult).Single() * 0.4) + (GradeResult.Where(x => x.MajorID == 3).Select(x => x.MajorResult).Single() * 0.6) });
    }

    if((ExamResult[2].MajorResult == LowestRank1.MajorResult) && (GradeResult[2].MajorResult == LowestRank2.MajorResult))
    {
        Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 1).Select(x => x.MajorDescription).Single(), Value = (ExamResult.Where(x => x.MajorID == 1).Select(x => x.MajorResult).Single() * 0.4) + (GradeResult.Where(x => x.MajorID == 1).Select(x => x.MajorResult).Single() * 0.6) });
        Rank.Add(new Ranking() { Name = ExamResult.Where(x => x.MajorID == 2).Select(x => x.MajorDescription).Single(), Value = (ExamResult.Where(x => x.MajorID == 2).Select(x => x.MajorResult).Single() * 0.4) + (GradeResult.Where(x => x.MajorID == 2).Select(x => x.MajorResult).Single() * 0.6) });
    }
}

1 个答案:

答案 0 :(得分:1)

假设

undefined

你可以计算每个专业的分数,如:

I  = Grades Result
II = Examination Result

A = Major A
B = Major B
C = Major C
对于主要的B和C来说,相同的是最好的。

((1 << (A.I - 1)) * 0.6) + ((1 << (A.II - 1)) * 0.4)

这只是因为你说最好的结果是1.你可以在int上只移7,在int64移15。

如果您有成绩或考试成绩,请告诉我&gt; 7或15