1061 True or False (15 points)

1061 True or False (15 points)

The judgment of true or false questions is very simple. This question requires you to write a simple program to help the teacher judge the questions and count the scores of the students on the true or false questions.

Input format:
Input two positive integers N and M not exceeding 100 in the first line, which are the number of students and the number of true or false questions respectively. The second line gives M positive integers not exceeding 5, which are the full marks of each question. The third line gives the correct answer to each question, 0 stands for "No", 1 stands for "Yes". Next N lines, each line gives a student's solution. The numbers are separated by spaces.

Output format:
output the scores of each student in the order of input, each score occupies one line.

Input sample:

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

Sample output:

13
11
12

answer

The map makes two mappings, corresponding to the score and the answer, and the key is the question number.
Output the total score of one line for each inspection line.


AC routine

#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
using namespace std;

int main()
{
    
    
#ifdef ONLINE_JUDGE
#else 
    freopen("in.txt","r",stdin);
#endif
int n,m,i,x,sum=0;
map<int,int>mp1;
map<int,int>mp2;
cin>>n>>m;
for(i=1;i<=m;i++)
{
    
    
    cin>>x;mp1[i]=x;
}
for(i=1;i<=m;i++)
{
    
    
    cin>>x;mp2[i]=x;
}
while(n--)
{
    
    
    sum=0;
    for(i=1;i<=m;i++)
{
    
    
    cin>>x;
    if(x==mp2[i])sum+=mp1[i];
}
cout<<sum<<endl;
}
return 0;
}

Guess you like

Origin blog.csdn.net/qq_41962612/article/details/114702164