1028. Census

Source: Internet
Author: User

A town carries out a census and gets the birthdays of all the residents. Please write a procedure to find the oldest and youngest person in town.

This ensures that every date entered is legal, but not necessarily reasonable-assuming that there are no older people over the age of 200 in the town, and today is September 6, 2014, it is unreasonable to have birthdays and birthdays that are over 200 years old and should be filtered out.

Input format:

The input gives the positive integer n in the first line, the value at (0,5], followed by n rows, each row gives the name of 1 persons (a string consisting of no more than 5 English letters), and a birthday given in the format "YYYY/MM/DD" (that is, the year/month/day). The title ensures that the oldest and youngest people are not tied up.

Output format:

The number of valid birthdays, the oldest person, and the most youthful name, in a single row, separated by a space.

#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 5typedef struct{int year;        int month;        int day; }people;bool Legal (People people); int Compare (People people1,people people2); People stan1={2014,9,6};    People stan2={1814,9,6};int Main () {int num;    scanf ("%d", &num);    GetChar ();    int i,count=0;    People people,old=stan1,young=stan2;    Char name[n+1],oldname[n+1],youngname[n+1];         for (i=0;i<num;i++) {scanf ("%s", name);         scanf ("%d/%d/%d", &people.year,&people.month,&people.day);             if (Legal (people)) {count++;                 if (Compare (people,old) <0) {old=people;                 strcpy (Oldname,name);                 } if (Compare (People,young) >0) {young=people;                 strcpy (Youngname,name); }}}//for if (count!=0) printf ("%d%s%s\n ", Count,oldname,youngname);    else printf ("0\n");    System ("pause");    return 0;    }int Compare (People people1,people people2) {if (people1.year>people2.year) return 1;         else if (people1.year==people2.year) {if (people1.month>people2.month) return 1;              else if (people1.month==people2.month) {if (people1.day>people2.day) return 1;              else if (People1.day==people2.day) return 0;              else return-1;         } else return-1;    } else return-1;     }bool Legal (People people) {if (Compare (people,stan1) >0) return false;     if (Compare (people,stan2) <0) return false;     return true; }

1028. Census

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.