pat1028--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, 105], 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.

Input Sample:

5John 2001/05/12tom 1814/09/06ann 2121/01/30james 1814/09/05steve 1967/11/20

Sample output:

3 Tom John
Overloading the operator is enough, wow. Do not need to use Set,vector, with the error, is to take the maximum minimum value!
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cctype>#include<cstdlib>#include<cmath>#include<string>#include<map>#include<Set>#include<queue>#include<vector>#include<stack>#include<cctype>using namespacestd;typedef unsignedLong Longull;#defineINF 0XFFFFFFFstructpeople{stringname; intYear,month,day; BOOL operator< (ConstPeople &p)Const    {        if(year==p.year) {if(month==p.month) {returnday<P.day; }            returnmonth<P.month; }        returnyear<p.year; }};intValid (People p) {intok=1; if(p.month<1|| P.month> A|| p.day<1|| P.day> to) OK=0; if(p.year<1814|| P.year> the) OK=0; Else if(p.year==1814&&p.month<9) OK=0; Else if(p.year==1814&&p.month==9&&p.day<6) OK=0; Else if(p.year== the&&p.month>9) OK=0; Else if(p.year== the&&p.month==9&&p.day>6) OK=0; returnOK;}intMain () {intn,x,y,i,j,k;    People p,p1,p2; CIN>>N; X=0;  for(i=0; i<n;++i) {cin>>P.name; scanf ("%d/%d/%d",&p.year,&p.month,&p.day); if(valid (p)) {++x; if(i==0) {P1=p2=p; }            if(p<p1) P1=p; if(p2<p) P2=p; }    }    if(x!=0) {cout<<x<<" "<<p1.name<<" "<<p2.name<<Endl; }    Else{printf ("0"); }        return 0;}

pat1028--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.