记录信息(record)

题目描述

利用动态链表输入、存储若干学生的信息,包括学号、姓名、性别、年龄、成绩,再按输入顺序倒叙输出。其中,学号长度不超过20个字符,姓名长度不超过40个字符,性别为一个字母f或m,年龄和成绩为一个整数。

输入

若干行,每一行都是一个学生的信息。例如 20170118 zhangsan m 15 100,其中的字符都是小写字母,输入以"end"结束。

输出

将输入的内容倒序输出,每行一条记录,按照学号、姓名、性别、年龄、成绩的格式输出。

样例输入

20170210 zhangsan f 16 100
20170140 wangyuan m 15 98
20170118 lisi f 14 65
20170928 zhaojing m 15 99
end

样例输出

20170928 zhaojing m 15 99
20170118 lisi f 14 65
20170140 wangyuan m 15 98
20170210 zhangsan f 16 100
#include <iostream>
using namespace std;
const int N = 100010;
int n = 0;
struct node {
	string id,name;
	char gender;
	int age,score;
	int prev,next;
}a[N];
int idx = 2,hh = 0,tt = 1;
void init () {
	a[hh].next = tt;
	a[tt].prev = hh;
}
void insert_right (int d,node x) {
	a[idx] = x;
	a[idx].next = a[d].next;
	a[a[d].next].prev = idx;
	a[idx].prev = d;
	a[d].next = idx++;
}
void insert_left (int d,node x) {
	d = a[d].prev;
	insert_right (d,x);
}
int main () {
	init (); //一定要初始化!!
	string id;
	while (cin >> id,id != "end") {
		string name;
		char gender;
		int age,score;
		cin >> name >> gender >> age >> score;
		insert_left (tt,{id,name,gender,age,score});
//		for (int i = a[hh].next;i != tt;i = a[i].next)  {
//			cout << a[i].id << ' ' << a[i].name  << ' ' << a[i].gender << ' ' << a[i].age << ' ' << a[i].score << endl;
//			cout << i << endl;
//		}
	}
//	for (int i = a[hh].next;i != tt;i = a[i].next)  {
//		cout << a[i].id << ' ' << a[i].name  << ' ' << a[i].gender << ' ' << a[i].age << ' ' << a[i].score << endl;
//		cout << i << endl;
//	}
	for (int i = a[tt].prev;i != hh;i = a[i].prev) {
		cout << a[i].id << ' ' << a[i].name  << ' ' << a[i].gender << ' ' << a[i].age << ' ' << a[i].score << endl;
	}
	return 0;
}
posted @   incra  阅读(210)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示