利用动态链表记录从标准输入输入的学生信息(学号、姓名、性别、年龄、得分、地址)
其中,学号长度不超过20, 姓名长度不超过40, 性别长度为1, 地址长度不超过40
包括若干行,每一行都是一个学生的信息,如:
00630018 zhouyan m 20 10.0 28#460
输入的最后以"end"结束
将输入的内容倒序输出
每行一条记录,按照
学号 姓名 性别 年龄 得分 地址
的格式输出
00630018 zhouyan m 20 10 28#4600 0063001 zhouyn f 21 100 28#460000 0063008 zhoyan f 20 1000 28#460000 0063018 zhouan m 21 10000 28#4600000 00613018 zhuyan m 20 100 28#4600 00160018 zouyan f 21 100 28#4600 01030018 houyan m 20 10 28#4600 0630018 zuyan m 21 100 28#4600 10630018 zouan m 20 10 28#46000 end
10630018 zouan m 20 10 28#46000 0630018 zuyan m 21 100 28#4600 01030018 houyan m 20 10 28#4600 00160018 zouyan f 21 100 28#4600 00613018 zhuyan m 20 100 28#4600 0063018 zhouan m 21 10000 28#4600000 0063008 zhoyan f 20 1000 28#460000 0063001 zhouyn f 21 100 28#460000 00630018 zhouyan m 20 10 28#4600
#include
using namespace std;
struct data{
char num[25], name[45], score[45], address[45];
char sex;
int age;
bool scan(){
scanf("%s", num);
if(strcmp(num, "end") == 0){
return true;
}
scanf("%s %c %d %s %s\n", name, &sex, &age, &score, address);
return false;
}
void print(){
printf("%s %s %c %d %s %s\n", num, name, sex, age, score, address);
}
};
struct node{
data d;
node *nxt, *pre;
}*head, *tail, *p;
int n, k;
int main(){
head = new node;
head -> pre = head -> nxt = NULL;
tail = head;
while(1){
p = new node;
if(p -> d.scan()){
break;
}
p -> pre = tail;
tail -> nxt = p;
p -> nxt = NULL;
tail = p;
}
p = tail;
while(p != head){
p -> d.print();
p = p -> pre;
}
return 0;
}