(PAT (Basic Level) Practice (中文)1058 选择题(C语言)
2019-01-14 18:38
357 查看
**程序员入门水平,贴出代码大家一起进步 **
批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。
输入格式:
输入在第一行给出``两个正整数 N(≤ 1000)和 M(≤ 100),分别是学生人数和多选题的个数。随后 M 行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N 行,每行给出一个学生的答题情况,其每题答案格式为 (选中的选项个数 选项1 ……),按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。
输出格式:
按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从 1 开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出 Too simple。
输入样例:
3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (2 b d) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (2 b c) (4 a b c d)
输出样例:
3
6
5
2 2 3 4
总结:
- 用一个结构体存放一道题目的正确答案信息。
- 设置一个静态二维数组存放成绩,初始化为0,要足够的大,不然最后一个测试点通不过。
- 学生的答案分行读取,然后设置两个指针,在函数中对答案用两个指针进行答案的判断,并设置函数进行判断答案的正误。
- 最后统计结时候进行一次遍历同时统计分数和错误题目的数量,否则会超时。
AC代码
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { int num[3]; char str[10]; }node; int main() { int ans(char *head,char *rear,char str[]); int N,M; scanf("%d %d",&N,&M); node answer[M]; int i; for(i=0;i<M;i++) { scanf("%d %d %d",&answer[i].num[0],&answer[i].num[1],&answer[i].num[2]); int t=0,j; char c; c=getchar(); while(c!='\n') { if(c!=' ') { answer[i].str[t]=c; t++; }; c=getchar(); }; answer[i].str[t]='\0'; }; int j,score[1010][110]={0}; for(i=0;i<N;i++) { char str[1500]; gets(str); char *head,*rear; head=str; rear=str; for(j=0;j<M;j++) { while(*head!='(')head++; while(*rear!=')')rear++; head+=3; rear-=1; if(ans(head,rear,answer[j].str)==0)score[i][j]=answer[j].num[0]; rear+=2; head=rear; }; }; for(i=0;i<N;i++) for(j=0;j<M;j++) { if(score[i][j]!=0)score[i][M]+=score[i][j]; else score [j]++; }; for(i=0;i<N;i++)printf("%d\n",score[i][M]); int max=0; for(j=0;j<M;j++)if(score [j]>max)max=score [j]; if(max==0)printf("%s","Too simple"); else { printf("%d ",max); int count=0; for(j=0;j<M;j++)if(score [j]==max)count++; for(j=0;j<M;j++) if(score [j]==max) { printf("%d",j+1); count--; if(count!=0)putchar(' '); }; }; return 0; } int ans(char *head,char *rear,char str[]) { char s[10]; int i=0; while(head<=rear) { if(*head!=' ') { s[i]=*head; i++; }; head++; }; s[i]='\0'; return strcmp(s,str); }
相关文章推荐
- PAT (Basic Level) Practice (中文)1061 判断题(C语言)
- PAT (Basic Level) Practice (中文)1072 开学寄语(C语言)
- PAT (Basic Level) Practice (中文)1069 微博转发抽奖(C语言)
- PAT (Basic Level) Practice (中文)1088 三人行(C语言)
- PAT (Basic Level) Practice (中文)1070 结绳(C语言)
- PAT (Basic Level) Practice (中文)1063 计算谱半径(C语言)
- PAT (Basic Level) Practice (中文)1077 互评成绩计算(C语言)
- PAT (Basic Level) Practice (中文)1080 MOOC期终成绩(C语言)
- PAT (Basic Level) Practice (中文)1089 狼人杀-简单版(C语言)
- PAT (Basic Level) Practise (中文) 1058. 选择题(20)
- PAT (Basic Level) Practice (中文)1066 图像过滤(C语言)
- PAT (Basic Level) Practice (中文)1081 检查密码(C语言)
- PAT (Basic Level) Practice (中文)1085 PAT单位排行(C语言)
- PAT (Basic Level) Practice (中文)1086 就不告诉你(C语言)
- PAT (Basic Level) Practice (中文)1075 链表元素分类(C语言)
- PAT (Basic Level) Practice (中文)1082 射击比赛(C语言)
- PAT (Basic Level) Practice (中文)1087 有多少不同的值(C语言)
- PAT (Basic Level) Practice (中文)1065 单身狗(C语言)
- PAT (Basic Level) Practise (中文)1058. 选择题(20)
- PAT (Basic Level) Practice (中文)1067 试密码(C语言)