打印学生的数据记录
时间: 1ms 内存:128M
描述:
现有N个学生的数据记录,每个记录包括学号、姓名、三科成绩。编写一个函数input,用来输入一个学生的数据记录。编写一个函数print,打印一个学生的数据记录。在主函数调用这两个函数,读取N条记录输入,再按要求输出。 N<100
输入:
学生数量N占一行每个学生的学号、姓名、三科成绩占一行,空格分开。
输出:
每个学生的学号、姓名、三科成绩占一行,逗号分开。
示例输入:
2
a100 zhblue 70 80 90
b200 newsclan 90 85 75
示例输出:
a100,zhblue,70,80,90
b200,newsclan,90,85,75
提示:
参考答案(内存最优[748]):
int N=100;
struct student
{char num[6];
char name[8];
int score[3];
}stu[100];
void print(struct student st)
{ int i,j;
printf("%s,%s",st.num,st.name);
for(j=0;j<3;j++)
printf(",%d",st.score[j]);
printf("\n");
}
main()
{int i,j ;
scanf ("%d",&N);
for(i=0;i<N;i++)
{
//printf("Input score of student %d:\n",i+1);
//printf("no.:");
scanf("%s",stu[i].num);
///printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{//printf("score%d:",j+1);
scanf("%d",&stu[i].score[j]);
}
print(stu[i]);
}
}
参考答案(时间最优[0]):
int N=100;
struct student
{char num[6];
char name[8];
int score[3];
}stu[100];
void print(struct student st)
{ int i,j;
printf("%s,%s",st.num,st.name);
for(j=0;j<3;j++)
printf(",%d",st.score[j]);
printf("\n");
}
main()
{int i,j ;
scanf ("%d",&N);
for(i=0;i<N;i++)
{
//printf("Input score of student %d:\n",i+1);
//printf("no.:");
scanf("%s",stu[i].num);
///printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{//printf("score%d:",j+1);
scanf("%d",&stu[i].score[j]);
}
print(stu[i]);
}
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。