PAT 乙级 1061 判断题 v1.0
1. 题目简述及在线测试位置
1.1 给定正确答案和学生答案,求每个学生的成绩
1.2 在线测试位置: 1061 判断题
2. 基本思路
2.1 使用结构体数组事半功倍:数组下标为题号、结构体中分别存储对应题目的得分和正确答案
#define MAX 100
struct Question
{
int FullScore;
bool RightAnswer;
};
struct Question Ques[MAX];
2.2 数据存储完毕,进行判定:比对正确答案和学生答案,若一致,增加学生得分
3. 完整AC代码
#include <iostream>
using namespace std;
#define MAX 100
struct Question
{
int FullScore;
bool RightAnswer;
};
int main()
{
struct Question Ques[MAX];
int StuNumber, QuesNumber;
int Sum; bool Answer;
cin >> StuNumber >> QuesNumber;
for (int i = 0; i < QuesNumber; i++)
cin >> Ques[i].FullScore;
for (int i = 0; i < QuesNumber; i++)
cin >> Ques[i].RightAnswer;
while (StuNumber--)
{
Sum = 0;
for (int i = 0; i < QuesNumber; i++)
{
cin >> Answer;
if (Ques[i].RightAnswer == Answer)
Sum += Ques[i].FullScore;
}
cout << Sum << endl;
}
return 0;
}