当前位置:网站首页>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 13912345678
The 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;
边栏推荐
- ASP. Net to access directory files outside the project website
- Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
- C语言指针经典面试题——第一弹
- Luogu deep foundation part 1 Introduction to language Chapter 4 loop structure programming (2022.02.14)
- Logstack configuration details -- elasticstack (elk) work notes 020
- Nuxt reports an error: render function or template not defined in component: anonymous
- Golang Modules
- Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
- Daughter love: frequency spectrum analysis of a piece of music
- C language pointer interview question - the second bullet
猜你喜欢
2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
Write a mobile date selector component by yourself
2022-2028 global visual quality analyzer industry research and trend analysis report
智慧路灯杆水库区安全监测应用
自动化的优点有哪些?
Hands on deep learning (33) -- style transfer
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
SQL replying to comments
技术管理进阶——如何设计并跟进不同层级同学的绩效
IIS configure FTP website
随机推荐
Report on investment analysis and prospect trend prediction of China's MOCVD industry Ⓤ 2022 ~ 2028
Kotlin:集合使用
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
Mmclassification annotation file generation
Normal vector point cloud rotation
C # use gdi+ to add text with center rotation (arbitrary angle)
MySQL foundation 02 - installing MySQL in non docker version
In the case of easyUI DataGrid paging, click the small triangle icon in the header to reorder all the data in the database
How to write unit test cases
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
How to batch change file extensions in win10
Qtreeview+ custom model implementation example
Investment analysis and future production and marketing demand forecast report of China's paper industry Ⓥ 2022 ~ 2028
Tkinter Huarong Road 4x4 tutorial II
[on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
Are there any principal guaranteed financial products in 2022?
ArrayBuffer
Kubernetes CNI 插件之Fabric
Ultimate bug finding method - two points
品牌连锁店5G/4G无线组网方案