1.题目如下:
判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。
输入格式:
输入在第一行给出两个不超过 100 的正整数 N 和 M,分别是学生人数和判断题数量。第二行给出 M 个不超过 5
的正整数,是每道题的满分值。第三行给出每道题对应的正确答案,0 代表“非”,1 代表“是”。随后 N
行,每行给出一个学生的解答。数字间均以空格分隔。
输出格式:
按照输入的顺序输出每个学生的得分,每个分数占一行。
输入样例:
3 6
2 1 3 3 4 5
0 0 1 0 1 1
0 1 1 0 0 1
1 0 1 0 1 0
1 1 0 0 1 1
输出样例:
13
11
12
代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MB
2.代码如下:
package pat_1061;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class testPractice1061 {
public static void main(String[] args) throws Exception{
try {
BufferedReader bf1=new BufferedReader(new InputStreamReader(System.in));
String str1=bf1.readLine();
int studentNumber=Integer.parseInt(str1.split(" ")[0]);
int choiceNumber=Integer.parseInt(str1.split(" ")[1]);
String str2=bf1.readLine();
String[] choiceGrade=str2.split(" ");
String str3=bf1.readLine();
String[] answer=str3.split(" ");
int sum=0;
int[] grade=new int[studentNumber];
for(int i=0;i<studentNumber;i++) {
sum=0;
String temp=bf1.readLine();
String[] studentAnswer=temp.split(" ");
for(int j=0;j<choiceNumber;j++) {
if(studentAnswer[j].equals(answer[j])) {
sum+=Integer.parseInt(choiceGrade[j]);
}
}
grade[i]=sum;
}
for(int i=0;i<studentNumber;i++) {
System.out.println(grade[i]);
}
bf1.close();
}catch(Exception ex) {
ex.printStackTrace();
}
}
}