当前位置:网站首页>7-2 keep the linked list in order
7-2 keep the linked list in order
2022-07-05 18:32:00 【mxrone】
For the information of several students entered , Establish an orderly linked list from small to large according to the student number , Finally, traverse the linked list , And output student information in order .
Input format :
First enter a positive integer T, Number of groups representing test data , And then there was T Group test data . First, input a positive integer for each group of test data n(1≤n≤100), Number of students . Then input n Line information , They are the student number and name of the student , among , The student number is 8 Bit positive integer ( Guarantees vary ), The name is no longer than 10 A string without spaces .
Output format :
For each group of tests , Output student information in order , Leave a space between student number and name ( See the output example ).
Input sample mile :
1
3
20080108 Zhangsan
20070328 Lisi
20070333 Wangwu
sample output :
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;
}
边栏推荐
- JVM third talk -- JVM performance tuning practice and high-frequency interview question record
- About Statistical Power(统计功效)
- 吳恩達團隊2022機器學習課程,來啦
- Introduction to VC programming on "suggestions collection"
- Tupu software digital twin | visual management system based on BIM Technology
- 关于服装ERP,你想知道的都在这里了
- Thoroughly understand why network i/o is blocked?
- Generate XML schema from class
- node_ Exporter memory usage is not displayed
- U-Net: Convolutional Networks for Biomedical Images Segmentation
猜你喜欢
爬虫01-爬虫基本原理讲解
The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
pytorch yolov5 训练自定义数据
About statistical power
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
U-Net: Convolutional Networks for Biomedical Images Segmentation
rust统计文件中单词出现的次数
Reading notes of Clickhouse principle analysis and Application Practice (5)
The 2022 China Xinchuang Ecological Market Research and model selection evaluation report released that Huayun data was selected as the mainstream manufacturer of Xinchuang IT infrastructure!
buuctf-pwn write-ups (9)
随机推荐
Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]
New words new words new words new words [2]
Pytorch yolov5 training custom data
Multithreading (I) processes and threads
vs2017 qt的各种坑
JVM third talk -- JVM performance tuning practice and high-frequency interview question record
IDEA配置npm启动
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
JDBC reads a large amount of data, resulting in memory overflow
LeetCode 6111. Spiral matrix IV
Is it safe to open an account, register and dig money? Is there any risk? Is it reliable?
记录Pytorch中的eval()和no_grad()
Can communication of nano
Cronab log: how to record the output of my cron script
Thoroughly understand why network i/o is blocked?
About Estimation with Cross-Validation
How to obtain the coordinates of the aircraft passing through both ends of the radar
buuctf-pwn write-ups (9)
Vulnhub's darkhole_ two
sample_rate(采样率),sample(采样),duration(时长)是什么关系