当前位置:网站首页>7-2 保持链表有序
7-2 保持链表有序
2022-07-05 18:22:00 【mxrone】
对于输入的若干学生的信息,按学号顺序从小到大建立有序链表,最后遍历链表,并按顺序输出学生信息。
输入格式:
首先输入一个正整数T,表示测试数据的组数,然后是T组测试数据。每组测试数据首先输入一个正整数n(1≤n≤100),表示学生的个数。然后输入n行信息,分别是学生的学号和姓名,其中,学号是8位的正整数(保证各不相同),姓名是长度不超过10且不含空格的字符串。
输出格式:
对于每组测试,按顺序输出学生信息,学号和姓名之间留一个空格(参看输出样例)。
输入样哩:
1
3
20080108 Zhangsan
20070328 Lisi
20070333 Wangwu
输出样例:
20070328 Lisi
20070333 Wangwu
20080108 Zhangsan#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stu{
int num;
char name[100];
struct stu *next;
};
int main(){
int n=0,m,i=0,j=0;
struct stu *head=NULL,*p,*tail,*q,*index,temp;
scanf("%d",&n);
while(i<n){
scanf("%d",&m);
for(j=0;j<m;j++){
p=(struct stu *)malloc(sizeof(struct stu ));
scanf("%d %s\n",&p->num,p->name);
if(head==NULL) head=tail=p;
else{
tail->next=p;
}
tail=p;
}
tail->next=NULL;
i++;
}
for(p=head;p!=NULL;p=p->next){
for(q=p->next;q!=NULL;q=q->next){
if(q->num<p->num){
temp.num=p->num;
strcpy(temp.name,p->name);
p->num=q->num;
strcpy(p->name,q->name);
q->num=temp.num;
strcpy(q->name,temp.name);
}
}
}
for(p=head;p!=NULL;p=p->next){
printf("%d %s\n",p->num,p->name);
}
return 0;
}
边栏推荐
- FCN: Fully Convolutional Networks for Semantic Segmentation
- Introduction to Resampling
- LeetCode 6109. 知道秘密的人数
- vulnhub之darkhole_2
- Image classification, just look at me!
- Numerical calculation method chapter8 Numerical solutions of ordinary differential equations
- Sophon CE Community Edition is online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
- Sibling components carry out value transfer (there is a sequence displayed)
- The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
- nano的CAN通信
猜你喜欢

小林coding的内存管理章节

Pytorch yolov5 training custom data

Thoroughly understand why network i/o is blocked?

吴恩达团队2022机器学习课程,来啦

Le cours d'apprentissage de la machine 2022 de l'équipe Wunda arrive.

吳恩達團隊2022機器學習課程,來啦

图像分类,看我就够啦!

U-Net: Convolutional Networks for Biomedical Images Segmentation

让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相

ConvMAE(2022-05)
随机推荐
How to improve the thermal management in PCB design with the effective placement of thermal through holes?
Einstein sum einsum
Simulate the hundred prisoner problem
图片数据不够?我做了一个免费的图像增强软件
@Extension, @spi annotation principle
FCN: Fully Convolutional Networks for Semantic Segmentation
pytorch yolov5 训练自定义数据
Use QT to traverse JSON documents and search sub objects
U-Net: Convolutional Networks for Biomedical Images Segmentation
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
RPC协议详解
Use of print function in MATLAB
【在優麒麟上使用Electron開發桌面應】
Crontab 日志:如何记录我的 Cron 脚本的输出
ClickHouse(03)ClickHouse怎么安装和部署
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
Privacy computing helps secure data circulation and sharing
含重复元素取不重复子集[如何取子集?如何去重?]
Is it safe for Apple mobile phone to speculate in stocks? Is it a fraud to get new debts?