Description
某单位有N名职工参加计算机水平考试,设每个人的数据包括准考证号、姓名、年龄、成绩。单位规定30岁以下的职工必须进行笔试,分数为百分制,60分为及格;30岁及以上的职工进行操作考试,成绩分为A,B,C,D四个等级,C以上为及格。编程统计及格人数,并输出每位考生的成绩。
Input
第一行输入N,连续输入N行,每行输入一位职工的职工准考证号、姓名、年龄;当年龄小于30时输入百分制成绩,年龄大于等于30时,输入A\B\C\D四个等级的成绩。
Output
输出为M行,M-1行为M-1位及格考生的成绩,最后一行为及格人数。
Sample Input
4
2001 zhang 25 80
2002 zhao 45 B
2003 qian 25 50
2004 wang 35 C
Sample Output
80
B
C
3
Source
#include<stdio.h>
struct studtype
{
int num;
char name[20];
int age;
union
{
int score;
char grade;
};
};
int main()
{
int N, i;
scanf("%d", &N);
struct studtype stu[N];
for(i = 0; i < N; i++)
{
scanf("%d%s%d", &stu[i].num, stu[i].name, &stu[i].age);
if(stu[i].age < 30)
scanf("%d", &stu[i].score);
else
{
getchar();
scanf("%c", &stu[i].grade);
}
}
int t = 0;
for(i = 0; i < N; i++)
if(stu[i].score >= 60 && stu[i].age < 30)
{
printf("%d\n", stu[i].score);
t++;
}
else if(stu[i].grade <= 'C' && stu[i].age >= 30)
{
printf("%c\n", stu[i].grade);
t++;
}
printf("%d", t);
return 0;
}