1061 判断题 (15 分)
判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。
输入格式:
输入在第一行给出两个不超过 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
下边给出思路:先输入三行数;
在把下边三行看成一个vector容器,对容器进行循环输入,判断新输入的temp
和 judge[j]是否相等
sum=sum+score[j];
在定义sum和score[i]相加
for(int i = 0; i < n; i++) {
int total = 0;
for(int j = 0; j < m; j++) {
int temp;
cin>>temp;
//scanf("%d", &temp);
if(temp == ans[j])
total += score[j];
}
下列给出循环,原谅小白无法从脑子计算出循环 当i=0 j=0 输入temp 0 1 1 0 0 1 时 ,if(0==ans[0]) 此时ans[0]=0;
i=1 代表着第一个同学 total=score[0]+total=2+0=2 j++=1;继续j循环
j<m=6;if 1==ans[1] 错误, 跳出if循环 j++=2
j<m=6 0==ans[2] 错误 跳出if循环 j++=3
------------------ 1== ans[5]正确 执行 total=score[5] j>m 跳出j循环
i=2 同学省略
i=3 同学省略
最后输出total,下面给出代码,个人感觉还是cin好使。。。。
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
// cin>>n>>m;
scanf("%d%d", &n, &m);
vector<int> score(m), ans(m);
for(int i = 0; i < m; i++)
//scanf("%d", &score[i]);
cin>>score[i];
for(int i = 0; i < m; i++)
// scanf("%d", &ans[i]);
cin>>ans[i];
for(int i = 0; i < n; i++) {
int total = 0;
for(int j = 0; j < m; j++) {
int temp;
cin>>temp;
//scanf("%d", &temp);
if(temp == ans[j])
total += score[j];
}
cout<<total<<endl;
// printf("%d\n", total);
}
return 0;
}
//printf("%d\n", total);
cout<<total;
}
return 0;
}