11219 - How old are you?

All about problems in Volume 112. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Shihab » Mon Nov 18, 2013 12:10 pm

WA , Please Help

Code: Select all

#include<cstdio>
#include<iostream>

using namespace std;

int test_case,age,flag,i=1;
int birth_date,birth_month,current_date,current_month;
int calculate_age();
long long birth_year,current_year;

int main()
{
    char slash;
    scanf("%d",&test_case);
    while(i<=test_case)
    {
        flag=0;
        scanf("%d%c%d%c%lld",&current_date,&slash,&current_month,&slash,&current_year);
        scanf("%d%c%d%c%lld",&birth_date,&slash,&birth_month,&slash,&birth_year);
        if(current_year<birth_year)
        {
            printf("Case %d: Invalid birth date",i);
        }
        else if(current_year==birth_year)
        {
            if(current_month>=birth_month)
            {
                if(current_date<=birth_date)
                {
                    age=calculate_age();
                    flag=1;
                }
                else
                {
                    printf("Case %d: Invalid birth date",i);
                }
            }
            else
            {
                printf("Case %d: Invalid birth date",i);
            }
        }
        else
        {
            flag=1;
            age=calculate_age();
            if(current_month==birth_month)
            {
                if(current_date<birth_date)
                    age--;
            }
            if(current_month<birth_month)
            {
                age--;
            }

        }
        if(flag==1)
        {
            if(age>=130)
                printf("Case %d: Check birth date",i);
            else
                printf("Case %d: %d",i,age);
        }
        i++;

    }
    return 0;
}

int calculate_age()
{
    return current_year-birth_year;
}




brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by brianfry713 » Mon Nov 18, 2013 10:54 pm

Print a newline char at the end of each line.
Check input and AC output for thousands of problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Shihab » Tue Nov 19, 2013 1:52 pm

Why should I ?
Can u tell me the reason.
Still WA

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by brianfry713 » Wed Nov 20, 2013 1:47 am

For the sample input, the correct output is:

Code: Select all

Case #1: Invalid birth date
Case #2: Check birth date
Case #3: 23
Case #4: 0
Your output is:

Code: Select all

Case 1: Invalid birth dateCase 2: Check birth dateCase 3: 23Case 4: 0
Your output is wrong. Post your updated code if you're still having trouble.
Check input and AC output for thousands of problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Shihab » Wed Nov 20, 2013 7:47 am

Code Updated

Code: Select all


#include<cstdio>
#include<iostream>

using namespace std;

int test_case,age,flag,i=1;
int birth_date,birth_month,current_date,current_month;
int calculate_age();
long long birth_year,current_year;

int main()
{
    char slash;
    scanf("%d",&test_case);
    while(i<=test_case)
    {
        flag=0;
        scanf("%d%c%d%c%lld",&current_date,&slash,&current_month,&slash,&current_year);
        scanf("%d%c%d%c%lld",&birth_date,&slash,&birth_month,&slash,&birth_year);
        if(current_year<birth_year)
        {
            printf("Case #%d: Invalid birth date\n",i);
        }
        else if(current_year==birth_year)
        {
            if(current_month>=birth_month)
            {
                if(current_date<=birth_date)
                {
                    age=calculate_age();
                    flag=1;
                }
                else
                {
                    printf("Case #%d: Invalid birth date\n",i);
                }
            }
            else
            {
                printf("Case #%d: Invalid birth date\n",i);
            }
        }
        else
        {
            flag=1;
            age=calculate_age();
            if(current_month==birth_month)
            {
                if(current_date<birth_date)
                    age--;
            }
            if(current_month<birth_month)
            {
                age--;
            }

        }
        if(flag==1)
        {
            if(age>=130)
                printf("Case #%d: Check birth date\n",i);
            else
                printf("Case #%d: %d\n",i,age);
        }
        i++;

    }
    return 0;
}

int calculate_age()
{
    return current_year-birth_year;
}




brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by brianfry713 » Wed Nov 20, 2013 11:03 pm

Input:

Code: Select all

1

01/02/2130
01/01/2000
Output should be:

Code: Select all

Case #1: 130
Check input and AC output for thousands of problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Shihab » Thu Nov 21, 2013 12:04 pm

Still WA

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by brianfry713 » Thu Nov 21, 2013 8:37 pm

The code that you posted is still printing the wrong answer for the input I posted. Post your updated code if you want more help.
Check input and AC output for thousands of problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Shihab » Sun Nov 24, 2013 10:04 am

Code Updated

Code: Select all

#include<cstdio>
#include<iostream>

using namespace std;

int test_case,age,flag,i=1;
int birth_date,birth_month,current_date,current_month;
int calculate_age();
long long birth_year,current_year;

int main()
{
    char slash;
    scanf("%d",&test_case);
    while(i<=test_case)
    {
        flag=0;
        scanf("%d%c%d%c%lld",&current_date,&slash,&current_month,&slash,&current_year);
        scanf("%d%c%d%c%lld",&birth_date,&slash,&birth_month,&slash,&birth_year);
        if(current_year<birth_year)
        {
            printf("Case #%d: Invalid birth date\n",i);
        }
        else if(current_year==birth_year)
        {
            if(current_month>=birth_month)
            {
                if(current_date<=birth_date)
                {
                    age=calculate_age();
                    flag=1;
                }
                else
                {
                    printf("Case #%d: Invalid birth date\n",i);
                }
            }
            else
            {
                printf("Case #%d: Invalid birth date\n",i);
            }
        }
        else
        {
            flag=1;
            age=calculate_age();
            if(current_month==birth_month)
            {
                if(current_date<birth_date)
                    age--;
            }
            if(current_month<birth_month)
            {
                age--;
            }

        }
        if(flag==1)
        {
            if(age>130)
                printf("Case #%d: Check birth date\n",i);
            else
                printf("Case #%d: %d\n",i,age);
        }
        i++;

    }
    return 0;
}

int calculate_age()
{
    return current_year-birth_year;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by brianfry713 » Tue Nov 26, 2013 11:42 pm

Input:

Code: Select all

1

01/01/2000
02/01/2000
Correct output:

Code: Select all

Case #1: Invalid birth date
Check input and AC output for thousands of problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Shihab » Mon Dec 02, 2013 9:56 am

AC , thanks bryanfry

Ovro
New poster
Posts: 12
Joined: Mon Nov 11, 2013 8:30 am

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Ovro » Tue Dec 03, 2013 9:01 pm

Hello, Getting WA. Can someone tell me why ?

Code: Select all

#include<stdio.h>
int main()
{
    int x1,y1,z1,x2,y2,z2,test,i;
    long int day,age;
    scanf("%d",&test);
    for(i=1;i<=test;i++)
    {
        printf("\n");
        scanf("%d/%d/%d",&x1,&y1,&z1);
        scanf("%d/%d/%d",&x2,&y2,&z2);
        day=(x1+(y1-1)*30+z1*365)-(x2+(y2-1)*30+z2*365);
        if(day<0)
            printf("Case #%d: Invalid birth date\n",i);
        else
        {
            age=(day-day%365)/365;
            if(age>130)
                printf("Case #%d: Check birth date\n",i);
            else
                printf("Case #%d: %ld\n",i,age);
        }
    }
    return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by brianfry713 » Wed Dec 04, 2013 12:03 am

The output is comprised of one line for each input data set, don't print extra blank lines.
Check input and AC output for thousands of problems on uDebug!

B_sayem
New poster
Posts: 7
Joined: Wed Dec 11, 2013 7:57 pm

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by B_sayem » Sat Dec 14, 2013 5:20 pm

Why i got wrong ans??please reply.

Code: Select all

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,dd1,mm1,yy1,dd2,mm2,yy2,days1,days2,old,check=1;
    cin>>n;
    while(n>0)
    {
        cout<<endl;
        cin>>dd1;
        cin.ignore();
        cin>>mm1;
        cin.ignore();
        cin>>yy1;
        days1=(yy1*365)+(mm1*30)+dd1;
        cin>>dd2;
        cin.ignore();
        cin>>mm2;
        cin.ignore();
        cin>>yy2;
        days2=(yy2*365)+(mm2*30)+dd2;
        //cout<<endl;
        if(days2>days1)
        {
            cout<<"Case #"<<check<<": "<<"Invalid birth date"<<endl;
        }
        else
        {
            old=(days1-days2)/365;
            if(old>130)
            {
                cout<<"Case #"<<check<<": "<<"Check birth date"<<endl;
            }
            else
            cout<<"Case #"<<check<<": "<<old<<endl;
        }

        check++;
        n--;
    }

    return 0;
}

Yousuf
New poster
Posts: 13
Joined: Thu Jun 09, 2011 8:22 am

Re: [11219 - How old are you?] Wrong Answer!! Plz help me

Post by Yousuf » Sat Dec 14, 2013 9:40 pm

Why you are printing an extra line at the beginning of every test case. You don't need that. Check output format carefully. Hope its helps :) .

Post Reply

Return to “Volume 112 (11200-11299)”