简单题...
悲剧的是第一次边下载软件安装边做
居然卡机了, 之后就去吃饭了,让它慢慢恢复吧
可恶的是回来还是老样子...无奈只好重启
晕...重启后就没了, 而且也不短
虽然不难,但也不短啊...晕
还是自己写的排序(当review...)
还好第二次做交了...1A...哈哈
2010-11-27 20:07:40 Accepted 1236 46MS 232K 2281 B C Y
#include <string.h>
#define reg_len 21
int *prob; /* 题目分值 */
typedef struct {
char reg_num[reg_len]; /* 准考证号 */
int grade; /* 总分 */
}student;
typedef student *Student;
Student stu; /* 学生量 */
/* 先按成绩递减排序, 再按准考证号递增排序 */
void quick_sort(Student stu, int x, int y)
{
int i, j;
student tmp;
if (x >= y)
{
return;
}
i = x;
j = y;
tmp = stu[x];
while (i < j)
{
while (i < j && (tmp.grade > stu[j].grade
|| (tmp.grade == stu[j].grade
&& strcmp(tmp.reg_num, stu[j].reg_num) < 0) ))
{
j--;
}
if (i < j)
{
stu[i] = stu[j];
i++;
}
while (i < j && (tmp.grade < stu[i].grade
|| (tmp.grade == stu[i].grade
&& strcmp(tmp.reg_num, stu[i].reg_num) > 0)))
{
i++;
}
if (i < j)
{
stu[j] = stu[i];
j--;
}
}
stu[j] = tmp;
quick_sort(stu, x, j - 1); /* 左边 */
quick_sort(stu, j + 1, y); /* 右边 */
}
/* 统计符合要求的人数 */
int limit(Student stu, int len, int G)
{
int i;
for (i = 0; i < len; i++)
{
if (stu[i].grade >= G)
{
continue;
}
else
{
break;
}
}
return i;
}
/* 输出合格的 */
void print(Student stu, int limit)
{
int i;
printf("%d\n", limit);
for (i = 0; i < limit; i++)
{
printf("%s %d\n", stu[i].reg_num, stu[i].grade);
}
}
int main()
{
int N, M, G, i, j, index, len;
while (scanf("%d", &N), N)
{
scanf("%d%d", &M, &G);
if ((prob=(int *) calloc (M+1, sizeof(int))) == NULL) {
printf("空间分配失败!\n");
exit(-1);
}
if ((stu=(Student) calloc (N, sizeof(student))) == NULL) {
printf("空间分配失败!\n");
exit(-1);
}
/* 题目分值 */
for (i = 1; i <= M; i++)
{
scanf("%d", &prob[i]);
}
/* 每个学生考试的信息 */
for (i = 0; i < N; i++)
{
scanf("%s", stu[i].reg_num);
stu[i].grade = 0;
scanf("%d", &len);
for (j = 1; j <= len; j++) /* len为做出的题号 */
{
scanf("%d", &index); /* 做出的题号 */
stu[i].grade += prob[index];
}
}
quick_sort(stu, 0, N - 1);
len = limit(stu, N, G);
print(stu, len);
free( prob );
prob = NULL;
free( stu );
stu = NULL;
}
return 0;
}
Input
测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N
< 1000 )、考题数M ( 0 < M < = 10 )、分数线(正整数)G;
第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一
名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号
(题目号由1到M)。
当读入的考生人数为0时,输入结束,该场考试不予处理。
Output
对每场考试,首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高
到低输出上线考生的考号与分数,其间用1空格分隔。若有多名考生分数相同,则按他们考
号的升序输出。
Sample Input
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
1 2 40
10 30
CS001 1 2
2 3 20
10 10 10
CS000000000000000001 0
CS000000000000000002 2 1 2
0
Sample Output
3 CS003 60
CS001 37
CS004 37
0
1 CS000000000000000002 20