猿问

多选题评分算法 求指导

多选题评分规则

每个正确选项都有得分权重,选正确一个给该正确选项得分权重的分值,选错一个,则总分为0

假如:正确答案ABC ,总分10分,权重分别为 20% 40% 40%

提交答案 ABC 得 (20%+40%+40%)* 10 = 10分

提交答案 AB 得 (20%+40%)* 10 = 6分

提交答案 ABD 得 0分

集思广益,如果可以请使用PHP作答

拉莫斯之舞
浏览 946回答 8
8回答

慕盖茨4494581

function selectScore(preAnswerScore,answer) { let totalScore = 0; let noScoreKey = []; let hasNoScoreKey = false; for(let key in preAnswerScore) { if(preAnswerScore[key] == 0){ noScoreKey.push(key); } } noScoreKey.map( item => { if(answer.includes(item)){ hasNoScoreKey = true; } }); if(hasNoScoreKey) { totalScore = 0; }else{ answer.map (item => { totalScore += preAnswerScore[item]; }); totalScore /= 10; } return totalScore; } let preAnswerScore = {a: 20, b: 40, c: 40, d: 0}; let answer = ['c','b','d'] console.log(selectScore(preAnswerScore, answer)); } js走一波,考虑到你其他选择题也适用

守着星空守着你

不会php, 用一下js // 选择的选项 const select = ['a','b','d'] // 分数 const score = { 'a': 20, 'b': 20, 'c': 60, 'd': 0 } // 根据所选 得到 分数如:abd 的到 20,20,0 const a = select.map(x => score[x]) // 如果 a里面有 0 直接返回 0 否则 reduce 后得到 分数 total = a.includes(0) ? 0 : a.reduce((total, i) => total+ (i *0.1) , 0)

繁华开满天机

思路,获得提交与答案的交集,如果交集个数不等于提交个数,则认为,存在选错的值,如果交集个数等于提交个数,遍历求分即可 <?php function multiSelectScore($answer, $wight, $allScore, $submit) { $score = 0; $answerWight = array_combine($answer, $wight); // 计算交集 $selects = array_intersect($answer, $submit); if(count($selects) === count($submit)) { // 遍历交集 foreach($selects as $key => $select) { $score += $answerWight[$select] * 0.01 * $allScore; } } return $score; } // 答案 $answer = ["A", "B", "C"]; // 权重 $wight = ["20","30","50"]; // 总分 $allScore = 10; // 提交的选项 $submit = ["A","C"]; $score = multiSelectScore($answer, $wight, $allScore, $submit); echo json_encode($score) . "\n";

慕少森

function calc($result,$answer,$score){ $count = count($result); $d = array_diff($answer,$result); if($d){ return 0; } $c = array_diff($result,$answer); $lost = count($c); if(!$lost){ return $score; } switch ($count) { case 1: $per = [1=>1]; break; case 2: $per = [1=>0.4,2=>1]; break; case 3: $per = [1=>0.2,2=>0.6,3=>1]; break; default: $per = [1=>0.1,2=>0.5,3=>0.8,4=>1]; break; } $true = $count - $lost ; return $per[$true]*$score; } $result = ['A','B','C']; $answer = ['A','B']; $score = 10; echo calc($result,$answer,$score);

哈士奇WWW

function check_score(array $answer, array $correct, $total_score){ $answer=array_flip($answer); $check=array_intersect_key($correct, $answer); return in_array($check, 0) ? 0 : array_sum($ckeck)*$total_score; } $answer为答案数组(['A', 'B', 'C']) $correct为正确答案数组(['A'=>0.2, 'B'=>0.4, 'C'=>0.4, 'D'=>0]) $total_score为总分 首先翻转$answer让选项成为key(['A'=>0, 'B'=>1, 'C'=>2]) 然后根据key计算$correct和$answer的交集$check,$check的key和value都保留$correct的。 检查$check的value中是否有0,有的话说明有错误答案,返回0分,否则计算$check的value的和,并乘以总分返回。
随时随地看视频慕课网APP
我要回答