天天看點

PAT 乙級 1061  判斷題

1061 判斷題 (15 point(s))

判斷題的評判很簡單,本題就要求你寫個簡單的程式幫助老師判題并統計學生們判斷題的得分。

輸入格式:

輸入在第一行給出兩個不超過 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      

經驗總結:

AC代碼 

#include <cstdio>
#include <cstring>
int main()
{
  int n,m,score[110];
  bool answer[110];
  while(~scanf("%d %d",&n,&m))
  {
    memset(score,0,sizeof(score));
    memset(answer,0,sizeof(answer));
    for(int i=0;i<m;++i)
      scanf("%d",&score[i]);
    for(int i=0;i<m;++i)
      scanf("%d",&answer[i]);
    for(int i=0;i<n;++i)
    {
      int res=0,temp;
      for(int j=0;j<m;++j)
      {
        scanf("%d",&temp);
        if(temp==answer[j])
          res+=score[j];
      }
      printf("%d\n",res);
    }
  }
  return 0;
}