排名有关问题
排名问题九度OJ终于把所有的一星题目AC了,现在开始二星的征程。唉,吐草一下,人家高帅富假期都去各种潇洒,我
排名问题
九度OJ终于把所有的一星题目AC了,现在开始二星的征程。唉,吐草一下,人家高帅富假期都去各种潇洒,我这种拼命的人只能往死里学习编程了,加油,我相信终有一天我会成功的!
- 题目描述:
- #include <stdio.h>#include <stdlib.h>#include <string.h>struct student{char name[21];//学生考号int count;//学生ac的题目总数int grade;//学生的总得分};int main(){int n, m, g, i, j, topic, fail_number;struct student students[1001];int score[11];while(scanf("%d",&n) != EOF){if(n == 0){break;}scanf("%d %d",&m,&g);//记录每到题的分数for(i = 0; i < m; i++){scanf("%d",&score[i]);}//记录学生的成绩int k = 0;for(i = 0; i < n; i++){students[i].grade = 0;scanf("%s",students[i].name);scanf("%d",&students[i].count);for(j = 0; j < students[i].count; j++){scanf("%d",&topic);students[i].grade += score[topic - 1];}if(students[i].grade >= g)k ++;}//输出及格同学的学号和分数(冒泡排序)for(i = 0; i < n - 1; i++){for(j = 0; j < n - 1 -i; j ++){if(students[j].grade > students[j + 1].grade){struct student temp;temp = students[j];students[j] = students[j + 1];students[j + 1] = temp;}else if (students[j].grade == students[j + 1].grade){if(strcmp(students[j].name,students[j + 1].name) < 0){struct student temp;temp = students[j];students[j] = students[j + 1];students[j + 1] = temp;}}}}if(k > 0){printf("%d\n",k);for(i = n -1; i >= n - k; i--){printf("%s %d\n",students[i].name,students[i].grade);}}else{printf("%d\n",k);}}return 0;}