数据结构:统计学生信息(c++动态链表完成)

6379:统计学生信息(使用动态链表完成)

描述

利用动态链表记录从标准输入输入的学生信息(学号、姓名、性别、年龄、得分、地址)其中,学号长度不超过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<bits/stdc++.h>
  using namespace std;
  struct node
  {
      string st;
      struct node *pre;
  };
  
  int main()
{
     int i;
     string s;
     struct node *head,*t;
     head=new struct node;
 
     getline(cin,s); 
     head->st=s; 
     head->pre=NULL;
     t=head;
 
     while (true)
     {
         getline(cin,s);
         if (s=="end"){ break; }
         head=new struct node;
         head->st=s;
         head->pre=t;
         t=head; 
     }
 
     head=new struct node;
     head->pre=t;
 
     while (head->pre!=NULL)
     {
         head=head->pre;
         cout<<head->st<<endl;    
     }
     return 0;
}

留个赞再走哦~

posted @ 2020-02-08 23:36  Kuller_Yan  阅读(127)  评论(0编辑  收藏  举报