当前位置:网站首页>Exercise 9-5 address book sorting (20 points)
Exercise 9-5 address book sorting (20 points)
2022-07-04 09:42:00 【skeet follower】
Input n A friend's information , Including name, 、 Birthday 、 Phone number , This question requires the preparation of procedures , Output the address book in order of age . The title ensures that everyone's birthday is different .
Input format :
Enter the first line to give a positive integer n(<10). And then n That's ok , Each line follows “ full name Birthday Phone number ” Give a friend's information in the format of , among “ full name ” It's no longer than 10 A string of English letters ,“ Birthday ” yes yyyymmdd Format date ,“ Phone number ” No more than 17 Digit numbers and +、- Composed string .
Output format :
Output your friends' information according to their age , The format is the same as that of output .
sample input :
3
zhang 19850403 13912345678
wang 19821020 +86-0571-88018448
qian 19840619 13609876543
sample output :
wang 19821020 +86-0571-88018448
qian 19840619 13609876543
zhang 19850403 13912345678The code is as follows :
#include<stdio.h>
#include<string.h>
int main()
{
struct friends{// Create structure
char name[11];// full name
long int birth;// Birthday
char number[18];// Phone number
};
struct friends s1[10];// Variable ;
int i,j,n;
int g[100];// Create an array to exchange information later ;
scanf("%d\n",&n);
for(i=0;i<n;i++){
scanf("%s %ld %s\n",s1[i].name,&s1[i].birth,s1[i].number);
}
for(i=0;i<n-1;i++){// Bubble sort compare size ;
for(j=0;j<n-i-1;j++){
if(s1[j].birth>s1[j+1].birth){
// Exchange birthdays , full name , Phone number ;
int temp=s1[j].birth;
s1[j].birth=s1[j+1].birth;
s1[j+1].birth=temp;
strcpy(g,s1[j+1].name);
strcpy(s1[j+1].name,s1[j].name);
strcpy(s1[j].name,g);
strcpy(g,s1[j+1].number);
strcpy(s1[j+1].number,s1[j].number);
strcpy(s1[j].number,g);
}
}
}
for(i=0;i<n;i++){
printf("%s %ld %s\n",s1[i].name,s1[i].birth,s1[i].number);
}
return 0;
}summary : This question mainly examines the structure , Bubble sort and library functions strcpy() Usage of ; If you are not proficient in bubble sorting, you can read this blog Ten classic sorting algorithms ( Dynamic diagram demonstration ) - A pixel - Blog Garden ;strcpy() usage c Language strcpy() usage _diyun The blog of -CSDN Blog _strcpy;
边栏推荐
- Hands on deep learning (39) -- gating cycle unit Gru
- 查看CSDN个人资源下载明细
- C language pointer classic interview question - the first bullet
- libmysqlclient. so. 20: cannot open shared object file: No such file or directory
- Ultimate bug finding method - two points
- Write a jison parser (7/10) from scratch: the iterative development process of the parser generator 'parser generator'
- Latex download installation record
- PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f
- Tkinter Huarong Road 4x4 tutorial II
- Some points needing attention in PMP learning
猜你喜欢

Hands on deep learning (33) -- style transfer

Hands on deep learning (32) -- fully connected convolutional neural network FCN

Hands on deep learning (34) -- sequence model

Fabric of kubernetes CNI plug-in

Four common methods of copying object attributes (summarize the highest efficiency)

Hands on deep learning (35) -- text preprocessing (NLP)

Hands on deep learning (38) -- realize RNN from scratch

直方图均衡化

El Table Radio select and hide the select all box

Summary of small program performance optimization practice
随机推荐
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
Markdown syntax
Golang type comparison
Hands on deep learning (37) -- cyclic neural network
MySQL foundation 02 - installing MySQL in non docker version
SQL replying to comments
回复评论的sql
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
Hands on deep learning (32) -- fully connected convolutional neural network FCN
Kubernetes CNI 插件之Fabric
Problems encountered by scan, scanf and scanln in golang
PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
Global and Chinese market of air fryer 2022-2028: Research Report on technology, participants, trends, market size and share
mmclassification 标注文件生成
xxl-job惊艳的设计,怎能叫人不爱
Get the source code in the mask with the help of shims
How do microservices aggregate API documents? This wave of show~
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f