当前位置:网站首页>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;
边栏推荐
- Global and Chinese market of bipolar generators 2022-2028: Research Report on technology, participants, trends, market size and share
- How do microservices aggregate API documents? This wave of show~
- 品牌连锁店5G/4G无线组网方案
- Write a jison parser from scratch (6/10): parse, not define syntax
- Dynamic analysis and development prospect prediction report of high purity manganese dioxide in the world and China Ⓡ 2022 ~ 2027
- Golang defer
- 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
- Summary of reasons for web side automation test failure
- C language pointer interview question - the second bullet
- Lauchpad X | 模式
猜你喜欢

Svg image quoted from CodeChina

回复评论的sql

H5 audio tag custom style modification and adding playback control events

PHP book borrowing management system, with complete functions, supports user foreground management and background management, and supports the latest version of PHP 7 x. Database mysql

The child container margin top acts on the parent container

2022-2028 global seeder industry research and trend analysis report

2022-2028 global probiotics industry research and trend analysis report

MATLAB小技巧(25)竞争神经网络与SOM神经网络

Daughter love: frequency spectrum analysis of a piece of music

智能网关助力提高工业数据采集和利用
随机推荐
In the case of easyUI DataGrid paging, click the small triangle icon in the header to reorder all the data in the database
Trees and graphs (traversal)
回复评论的sql
Write a jison parser (7/10) from scratch: the iterative development process of the parser generator 'parser generator'
Some points needing attention in PMP learning
Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027
Tkinter Huarong Road 4x4 tutorial II
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
If you can quickly generate a dictionary from two lists
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
Lauchpad X | 模式
Les différents modèles imbriqués de listview et Pageview avec les conseils de flutter
C language pointer classic interview question - the first bullet
Lauchpad x | MODE
C语言指针面试题——第二弹
How do microservices aggregate API documents? This wave of show~
Markdown syntax
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
Launpad | 基礎知識
Launpad | Basics