PAT Basic 1028 census (20 points)

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


#include <iostream>
using namespace std;
struct peo{
    string name;
    string date;
};
int main()
{
    int T;
    cin>>T;
    peo temp,old,young;
    int vali=0;bool flag=false;
    while(T--){
        cin>>temp.name>>temp.date;
        if(temp.date<="2014/09/06"&&temp.date>="1814/09/06"){
            vali++;
            if(!flag){
                old=temp;young=temp;
                flag=true;
            }else{
                if(temp.date<old.date) old=temp;
                if(temp.date>young.date) young=temp;
            }
        }
    }
    if(vali!=0) cout<<vali<<" "<<old.name<<" "<<young.name;
    else cout<<0;// here too little attention 
    System ( " PAUSE " );
     return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11286352.html