当前位置:网站首页>Exercise 9-5 address book sorting (20 points)
Exercise 9-5 address book sorting (20 points)
2022-06-11 22:25:00 【Xiaoyan y】
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
#include<stdio.h>
struct number{ // Define a structure type
char name[10]; // full name
long int birth; // Birthday
char tel[20]; // Phone number
};
int main(){
int n,i,j;
struct number s[10],temp; //s[10] Is to define an array of structures
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %ld %s ",&s[i].name,&s[i].birth,&s[i].tel);
}
for(i=0;i<n-1;i++){ // Structure array sorting , Choose the sorting method
for(j=i+1;j<n;j++){
if(s[i].birth>s[j].birth){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
for(i=0;i<n;i++){
printf("%s %ld %s\n",s[i].name,s[i].birth,s[i].tel);
}
return 0;
}summary :
1、 Definition of structure type :
struct Structure type name
{
data type Member name 1;
data type Member name 2;
......
data type Member name n;
};2、 The definition of structure explains the existence format of variables in the structure , To use this structure, you must specify the variables of the structure type . Structural variable theory The general form of Ming is as follows :
struct Structure type name Structure variable name ;3、 Structure array is a combination of structure and array , The difference from ordinary arrays is that each array element is data of a structure type .
4、 References to structural array element members are made by using array subscripts and structural member operators “.” A combination of ways to achieve , Its general format is :
Structure array name [ Subscript ]. Structure member name
边栏推荐
- A simple example of linear regression in machine learning
- Go OS module
- Is it safe for qiniu business school to send Huatai account? Really?
- 启牛推荐开通的证券账户安全吗?靠谱吗
- Determine whether the linked list is palindrome structure
- win10字体模糊怎么调节
- [nodejs] electron installation
- Go IO module
- astra pro双目相机ros下启动笔记
- SequenceList顺序表的实现
猜你喜欢

A simple example of linear regression in machine learning

Tkinter学习笔记(二)

Introduction to MySQL transactions

Learning bit segment (1)

C language to achieve eight sorts (2)

超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录

Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.2

leetcode 中的位运算

一款开源的Markdown转富文本编辑器的实现原理剖析

206. reverse linked list
随机推荐
Go OS module
电脑强制关机 oracle登录不上
leetcode 中的位运算
What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)
STM32 development note 113:ads1258 drive design - reading temperature value
Is the securities account recommended by qiniu safe? Is it reliable
链表基本操作与题型总结
习题11-2 查找星期 (15 分)
Tkinter study notes (II)
Neglected technique: bit operation
Nmap performs analysis of all network segment IP survivals in host detection
大学三年应该这样过
Tkinter学习笔记(三)
Go IO module
[uniapp native plug-in] shangmi cashbox plug-in
Basic operation of graph (C language)
How to view computer graphics card information in win11
238. product of arrays other than itself
[Yu Yue education] calculus of Zhejiang University in autumn and winter 2021 (I) reference materials
启牛商学院送华泰账户安不安全?真的吗