N Enter friend's information, including name, date of birth, telephone number, this question requires programming, by age descending order of output contacts. Topic ensure that all birthdays are not the same.
Input format:
input of the first row is given a positive integer n (<10). Then n lines of a friend give information in accordance with the "name birthday phone number" format, where "name" is no longer than 10 letters of the alphabet string consisting of "Birthday" is the date yyyymmdd format " phone number "is not more than 17 figures and +, - consisting of a string.
Output formats:
by age descending friends output, with output format.
Sample input:
. 3
Zhang 19,850,403 13912345678
Wang 19.82102 million + 86-0571-88018448
Qian 19,840,619 13,609,876,543
Output Sample:
Wang 19.82102 million + 86-0571-88018448
Qian 19,840,619 13,609,876,543
Zhang 19,850,403 13912345678
#include <stdio.h>
struct colleague
{
char name[11];
int birth;
char phone[18];
};
void sort_age(struct colleague *p, int n); 定义指向结构的指针
int main()
{
struct colleague my_friend[10];
int i, n;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%s %d %s", my_friend[i].name, &my_friend[i].birth, my_friend[i].phone);
sort_age(my_friend, n);
}
void sort_age(struct colleague *p, int n)
{
struct colleague temp;
int i, j;
for (i = 0; i < n - 1; i++) //冒泡排序
{
for (j = 0; j < n - 1 - i; j++)
{
if ((p+j)->birth > (p+j+1)->birth)
{
temp = *(p+j);
*(p+j) = *(p+j+1);
*(p+j+1) = temp;
}
}
}
for (i = 0; i < n; i++)
printf("%s %d %s\n", (p+i)->name, (p+i)->birth, (p+i)->phone);
}