PAT_B_1028 census

Subject description:

A town census, was the birthday of all residents. Now you write a program to find the town's oldest and most young people. 
Make sure that each date entered here are legitimate, but not necessarily reasonable - assuming there is no known town more than 200 years old, and today is September 6, 2014, the more than 200-year-old's birthday and not born birthday is unreasonable and should be filtered out. 
Input format: 
input given integer N in the first row, the values (0, 10 ^ 5]; followed by N rows, each row is given a name of an individual (not more than 5 by the letters of the English string), and date of birth as given in the format yyyy / mm / dd (that is, year / month / day) to ensure that the title of the oldest and the youngest person there is no parallel. 
output format: 
the output of a valid birth order in a row the number of young people and most of the oldest names, separated by spaces between them. 
sAMPLE iNPUT: 
5 
John 2001/05/12 
Tom 1814/09/06 
Ann 2121/01/30 
James 1814/09/05 
Steve 1967 / 11/20 
sample output: 
3 Tom John

I AC Code:

PAT_1028_Count_Population_02 // 

/ * 
 under * 1. Enter the format correct premise, a string of dates can be converted to an integer, directly determine the reasonableness of age 
 * 2. Before 2014/9/6 and 1814/9/6 after, not reasonable age 
 * 3. consider the case of full age unreasonable 
 * / 
#include <stdio.h> 
#include <string.h> 

int main () { 
    int N; // number 
    scanf ( "% d", & N); 
    name char [. 6], young_name [. 6], OLD_NAME [. 6]; 
    int year, month the, day, CNT = 0; // date, the number of effective birth 
    int maxAge = 2014 * 10000 + 9 * 100 + 6 ; // unreasonable critical point age 
    int minage = 1814 * 100 * 10000 + +. 9. 5; 
    for (int I = 0; I <N; I ++) { 
        Scanf ( "% S% D / D% / D%" , name, & year, month The &, & Day); 
        int year Age * = month The * 10000 + 100 + Day;  
        IF (Age <the maxAge && Age> minAge) {// If it is reasonable age
            CNT ++; 
            IF (Age <the maxAge) {// oldest 
                the maxAge = Age; 
                strcpy (OLD_NAME, name); 
            } 
            IF (Age> minage) {// youngest 
                minage = Age; 
                strcpy (young_name, name); 
            } 
        } 
    } 
    IF (CNT = 0!) { 
        the printf ( "% D% S% S \ n-", CNT, OLD_NAME, young_name); 
    } the else {// invalid birthday are all 
        the printf ( "0 \ n-"); 
    } 
    return 0; 
}

RRR

A town census, was the birthday of all residents. Now you write a program to find the town's oldest and most young people.

Make sure that each date entered here are legitimate, but not necessarily reasonable - assuming there is no known town more than 200 years old, and today is September 6, 2014, the more than 200-year-old's birthday and not born birthday is unreasonable and should be filtered out.

Input formats:

In the first line of the input is given a positive integer  N , the value ( ; then  N  rows, each individual is given a name (a string of not more than 5 letters of the English), and press  yyyy/mm/dd(i.e., year / month / day) birthday format given in the title to ensure the oldest and the youngest person not tied.

Output formats:

The number of valid order of the output birthday in a row, young people and most of the oldest names, separated by spaces between them.

Sample input:

5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20

Sample output:

3 Tom John

Guess you like

Origin www.cnblogs.com/Robin5/p/11243729.html