我在做考试系统,但是在评分的时候,要对多选题评分,多选没有分,少选有一半分
如:
正确答案ABC,分值是2
如果答题答案是:ABC 则给2分
如果答题答案是:AB 则给1分
如果答题答案是:A 则给1分
如果答题答案是:ABCD 则给0分请问如何实现这样的评分算法?
function int compare(key,testKey)
{}
如:
正确答案ABC,分值是2
如果答题答案是:ABC 则给2分
如果答题答案是:AB 则给1分
如果答题答案是:A 则给1分
如果答题答案是:ABCD 则给0分请问如何实现这样的评分算法?
function int compare(key,testKey)
{}
{
case:
}
我的意思是要实现比较啊,函数要实现
eg:
compare("ABC","AC")=1 //不全对
compare("ABD","ABCD")=0 //错
compare("ABD","ABC")=0 //错
compare("ABD","ABD")=2 //全对
能帮我写个算法吗
{
/// <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; // 没有做答
}
}
}
}