我在做考试系统,但是在评分的时候,要对多选题评分,多选没有分,少选有一半分
如:
正确答案ABC,分值是2
如果答题答案是:ABC 则给2分
如果答题答案是:AB 则给1分
如果答题答案是:A 则给1分
如果答题答案是:ABCD 则给0分请问如何实现这样的评分算法?
function int compare(key,testKey)
{}

解决方案 »

  1.   

    switch()
    {
        case:
    }
      

  2.   

    to hunter_32(曠野裡奔嘯的狼) 
    我的意思是要实现比较啊,函数要实现
    eg: 
    compare("ABC","AC")=1   //不全对
    compare("ABD","ABCD")=0 //错
    compare("ABD","ABC")=0  //错
    compare("ABD","ABD")=2  //全对
      

  3.   

    试试看用遍历testkey的每一个字符,然后用key.IndexOf()去匹配,如果有-1的人为是错,如果>0,则Count++,最后如果count的大小和testkey的字符串长度一致,认为全对,小于则半对
      

  4.   

    to terryshi(terryshi)
    能帮我写个算法吗
      

  5.   

    using System;namespace ConsoleApplication12
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    class Class1
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    Console.WriteLine(Compare("ABC", "BAC"));
    Console.WriteLine(Compare("ABC", "B"));
    Console.WriteLine(Compare("ABC", "BACD"));
    Console.WriteLine(Compare("ABC", ""));
    }
    public static int Compare(string key, string testKey) {
    int i_Index;
    int i_Count = 0; foreach(Char c_Tmp in testKey.ToCharArray()) {
    i_Index = key.IndexOf(c_Tmp);
    if (i_Index < 0) {
    return 0;       // 错误
    } else {
    i_Count ++;
    }
    } if (i_Count == key.Length) {
    return 2;   // 正确
    } else if (i_Count > 0) {
    return 1;   // 半对
    } else {
    return 0;   // 没有做答
    }
    }
    }
    }