完成对一个顺序表的建立,表中的每个元素是同学们的学号、姓名和三门课程的成绩,输入5个同学的信息,然后显示在屏幕上。(要求利用顺序表的基本操作)
输入格式:
首先收入学生人数5,然后依次输入5个学生的学号、姓名和三门课的成绩
输出格式:
输入5个学生的学号、姓名和三门课的成绩
输入样例:
5 01 张三 89 89 89 02 李四 90 90 90 03 王五 89 89 89 04 钱六 97 97 97 05 赵倩 90 90 90
输出样例:
1 张三 89.0 89.0 89.0 2 李四 90.0 90.0 90.0 3 王五 89.0 89.0 89.0 4 钱六 97.0 97.0 97.0 5 赵倩 90.0 90.0 90.0
人生中第一个线性表的题,纪念一下。
直接全输出会格式错误,竟然是要换行,但是输出样例里完全没有体现出来。
#include<iostream>
#define MAXSIZE 100
using namespace std;
int main()
{
typedef struct
{
int num;
string name;
double a,b,c;
}SqList;
SqList student[5];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>student[i].num>>student[i].name>>student[i].a>>student[i].b>>student[i].c;
}
cout.precision(1);
for(int i=0;i<n;i++)
{
cout<<student[i].num<<" "<<student[i].name<<" "<<fixed<<student[i].a<<" "<<fixed<<student[i].b<<" "<<fixed<<student[i].c;
if(i!=n-1) cout<<endl;
}
return 0;
}