PAT (Basic Level) 1061 判断题 (15分)JAVA解法

在这里插入图片描述

输入样例:

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



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
 * 输入格式:
输入在第一行给出两个不超过 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

 * **/
public class Main {
static int Sum =0;
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] temp1 = br.readLine().split(" ");
		int Snum = Integer.parseInt(temp1[0]);
		int Tnum = Integer.parseInt(temp1[1]);
		String[] Score = br.readLine().split(" ");
		String[] TrueT = br.readLine().split(" ");
		
		while(Snum!=0) {
			String[] choose = br.readLine().split(" ");
			for (int i = 0; i < choose.length; i++) {
				int c = Integer.parseInt(choose[i]);
				int t = Integer.parseInt(TrueT[i]);
				if(c==t) {
					Sum+=Integer.parseInt(Score[i]);
				}
			}
			System.out.println(Sum);
			Sum=0;
			Snum--;
		}
		
		
		
	}

}

在这里插入图片描述

发布了83 篇原创文章 · 获赞 1 · 访问量 1024

猜你喜欢

转载自blog.csdn.net/qq_44028719/article/details/103992618
今日推荐