题目链接:https://noi.vip/problem/1036
代码随意,语言随意,在连接上面AC了即可
使用头插法将输入数据加入链表,然后按链表顺序输出即可
#include <iostream>
using namespace std;
typedef struct _student
{
char id[20];
char name[40];
char sex;
int age;
int score;
char addr[40];
}student;
typedef struct _node
{
student stu;
struct _node *next;
}node;
int main()
{
node *head = (node*)malloc(sizeof(node));
head->next = NULL;
//
student s;
while(scanf("%s %s %c %d %d %s",s.id,s.name,&s.sex,&s.age,&s.score,s.addr) == 6)
{
node *p = (node*)malloc(sizeof(node));
p->stu = s;
p->next = head->next;
head->next = p;
}
node *p = head->next;
while(p != NULL)
{
printf("%s %s %c %d %d %s\n",p->stu.id,p->stu.name,p->stu.sex,p->stu.age,p->stu.score,p->stu.addr);
p = p->next;
}
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!