9Google AdSense

ACM Problem Solution : How old are you? - 11219

View Code
View Problem
-------------------------------------------------------------------------------------

#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
    int day,month,year,age,t,day1,month1,year1,i;
    char ch;
    scanf("%d",&t);
    i=0;
    while(t--)
    {
        i++;
        scanf("%d%c%d%c%d",&day,&ch,&month,&ch,&year);
        scanf("%d%c%d%c%d",&day1,&ch,&month1,&ch,&year1);
        age=year-year1;
        if((month1>month)||((month==month1)&&(day<day1)))
            age=age-1;
        if(age<0)
            cout<<"Case #"<<i<<":"<<" "<<"Invalid birth date"<<endl;
        else if(age>130)
            cout<<"Case #"<<i<<":"<<" "<<"Check birth date"<<endl;
        else
            cout<<"Case #"<<i<<":"<<" "<<age<<endl;
    }
    return 0;
} 


No comments: