我有2个数组 - 1个多维,其中列描述答案和行 - 学生。第二个是具有正确答案的解决方案阵列。 我需要编写方法来查找哪些行有相同的错误答案(某种反作弊),它返回多维数组,其中index表示student,每个子数组列表 所有在该指数上对学生有类似错误答案的学生的指数。
以下是我尝试的方法: int num - 表示计算错误答案的阈值。
public static int[][] findSimilarAnswers(int num,char[][] responses,char[] solutions){
int[][] stats = new int[responses.length][];
for (int i = 0; i < responses.length; i++) {
int length = numMatches(responses,solutions,i,num);
int[] wrongs = new int[length];
for (int j = 0; j < wrongs.length; j++) {
wrongs[j] = numWrongSimilar(responses[i],responses[i],solutions);
}
stats[i] = wrongs;
}
return stats;
}
方法numWrongSimilar
比较两个数组的错误答案并返回错误答案的数量:
public static int numWrongSimilar(char[]studentOneResponse,char[]studentTwoResponse,char[] solutions){
int wrong = 0;
for (int i = 0; i < solutions.length; i++) {
if(studentOneResponse[i] != solutions[i]
&& studentOneResponse[i] == studentTwoResponse[i])
wrong++;
}
return wrong;
}
和方法numMatches
找出哪些错误答案高于阈值。
以下是回复和解决方案的数组。
char[][] responses = { {'C', 'A', 'B', 'B', 'C', 'A'},
{'A', 'A', 'B', 'B', 'B', 'B'},
{'C', 'B', 'A', 'B', 'C', 'A'},
{'A', 'B', 'A', 'B', 'B', 'B'}
};
char[] solutions = {'C', 'A', 'B', 'B', 'C', 'C'};
使用此数组和阈值3
必须返回
[[], [3], [], [1]]
但它会返回[[], [3], [], [5]]
好像我在这里写错了行wrongs[j] = numWrongSimilar(responses[i],responses[i],solutions);
但我该如何正确地重写呢?