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

rahat khan
New poster
Posts: 10
Joined: Mon May 23, 2011 1:12 pm

Re: 11219 - How old are you/

Post by rahat khan » Mon May 23, 2011 1:31 pm

#include<stdio.h>
int main()
{
int a,b,c,d,e,f,g,h,i,j,T;
scanf("%d",&T);
for(j=1;j<=T;j++)
{
scanf("%d/%d/%d%d/%d/%d",&a,&b,&c,&d,&e,&f);
if(a>d)
{
if(b>e)
{
i=c-f;
}
if(b<e)
{
f=f+1;
i=c-f;
}
}
if(a<d)
{
e=e+1;
if(b>=e)
{
i=c-f;
}
if(b<e)
{
f=f+1;
i=c-f;
}
}
if (i<0)
printf("Case #%d: Invalid birth date\n",j);
else if(i>130)
printf("Case #%d: Check birth date\n",j);
else if(0<=i<=130)
printf("Case #%d: %d\n",j,i);
}
return 0;

}

rahat khan
New poster
Posts: 10
Joined: Mon May 23, 2011 1:12 pm

10075

Post by rahat khan » Thu May 26, 2011 9:12 pm

#include<stdio.h>
int main()
{
int s,v,t;
scanf("%d %d",&v,&t);
s=v*t*2;
printf("%d\n",s);
return 0;
}

tanvirfromhell
New poster
Posts: 5
Joined: Sat Apr 16, 2011 7:42 pm

Re: 11219 - How old are you?

Post by tanvirfromhell » Mon Jun 13, 2011 3:01 pm

why I got WA? I was check every input set (including from here). but still WA?!! :x :x :x Help me frndz

Code: Select all

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,i;
    int dt1,mn1,yr1,dt2,mn2,yr2;
    char a1,b1,a2,b2;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%c%d%c%d",&dt1,&a1,&mn1,&b1,&yr1);
        scanf("%d%c%d%c%d",&dt2,&a2,&mn2,&b2,&yr2);
        if((yr1<yr2) || (yr1==yr2 && mn1<mn2) || (yr1==yr2 && mn1==mn2 && dt1<dt2))
            printf("Case #%d: Invalid birth date\n",i);

        if((yr1-yr2==131 && mn1<mn2) || (yr1-yr2==131 && mn1==mn2 && dt1<dt2))
            printf("Case #%d: 130\n",i);

        else if((yr1-yr2>130) || (yr1-yr2>130 && mn1==mn2 && dt1>dt2))
            printf("Case #%d: Check birth date\n",i);

        if(yr1-yr2<=130 && yr1-yr2>1)
            printf("Case #%d: %d\n",i,yr1-yr2);


        if((yr1-yr2==1) || (yr1==yr2 && mn1>mn2) || (yr1==yr2 && mn1==mn2 && dt1>dt2) || (yr1==yr2 && mn1==mn2 && dt1==dt2))
           printf("Case #%d: 0\n",i);
    }
    return 0;
}

newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 11219 - How old are you?

Post by newkid » Mon Jun 13, 2011 11:28 pm

Try this input

Code: Select all

1

19/02/2012
19/03/2010
Output should be

Code: Select all

Case #1: 1
Your code prints

Code: Select all

Case #1: 2
hmm..

rahat khan
New poster
Posts: 10
Joined: Mon May 23, 2011 1:12 pm

Re: 10035 Primary Arithmetic

Post by rahat khan » Thu Aug 04, 2011 10:39 am

#include<stdio.h>
int main()
{
long long a,b,c,m[100],n[100],x,y,i,e;
while(scanf("%lld %lld",&x,&y))
{
if(x==0&&y==0)
break;
c=0;
if(a<b)
{
a=y;
b=x;
}
else
{
a=x;
b=y;
}
e=0;
for(i=1;;i++)
{
m=a%10;
m=m+e;
a=a/10;
n=b%10;
b=b/10;
if((m+n)>9)
{
c++;
e++;
}
else
e=0;
if(a==0)
break;
}
if(c==0)
printf("No carry operation.\n");
else
printf("%lld carry operations.\n",c);
}
return 0;
}

AYAN
New poster
Posts: 3
Joined: Fri Jul 08, 2011 5:53 pm

Re: 11219 - How old are you?

Post by AYAN » Thu Sep 22, 2011 5:13 pm

WHY WA? CAN ANYONE HELP?
SOURCE CODE:
#include<stdio.h>
int main()
{
int c,t,d1,d2,m1,m2,y1,y2,year;
char s1[30],s2[30];
scanf("%d",&c);
for(t=1;t<=c;t++)
{
scanf("%s",s1);
sscanf(s1,"%d/%d/%d",&d1,&m1,&y1);
scanf("%s",s2);
sscanf(s2,"%d/%d/%d",&d2,&m2,&y2);
printf("Case #%d: ",t);
if(y2>y1)
printf("Invalid birth date\n");
else if(y2==y1)
{
if(m2>m1)
printf("Invalid birth date\n");
else if(m2==m1)
{
if(d2>d1)
printf("Invalid birth date\n");
else
printf("0\n");
}
else
printf("0\n");
}
else
{
year=y1-y2;
if(m2>m1)
year--;
else if(m2==m1)
{
if(d2>d1)
year--;
}
bool flag=1;
if(year>130)
{
printf("Check birth date\n");
flag=0;
}
else if(year==130)
{
if(m1>m2)
{
printf("Check birth date\n");
flag=0;
}
else if(m1==m2)
{
if(d1>=d2)
{
printf("Check birth date\n");
flag=0;
}
}
}
if(flag)
printf("%d\n",year);

}
}
return 0;
}

User avatar
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

11219 - How old are you? -->WA WA WA!!!

Post by shaon_cse_cu08 » Wed Nov 02, 2011 5:28 pm

I have tried every possible case given in this forum... But still WA... can ny1 help me... I can't sleep... :( :cry: :roll:

Code: Select all

#include<stdio.h>
int main()
{
    long day_1,mon_1,yr_1,day_2,mon_2,yr_2,t,cas;

    long yr_dif;

    scanf("%ld",&t);

    for(cas=1; cas<=t; cas++)
    {

        scanf("%ld/%ld/%ld",&day_1,&mon_1,&yr_1);
        scanf("%ld/%ld/%ld",&day_2,&mon_2,&yr_2);

        yr_dif=yr_1-yr_2;

        if((yr_1==yr_2)&&(day_1==day_2)&&(mon_1==mon_2))
            printf("Case #%ld: 0\n",cas);

        else if(yr_2>yr_1)
            printf("Case #%ld: Invalid birth date\n",cas);

        else if(yr_1==yr_2)
        {
            if(mon_2>mon_1)
                printf("Case #%ld: Invalid birth date\n",cas);

            else if(mon_2<mon_1)
                printf("Case #%ld: 0\n",cas);

            else
            {
                if(day_2>day_1)
                    printf("Case #%ld: Invalid birth date\n",cas);

                else if(day_2<day_1)
                    printf("Case #%ld: 0\n",cas);

            }

        }


        else if((yr_dif==1))
        {
            if(mon_2>mon_1)
                printf("Case #%ld: 0\n",cas);

            else if(mon_2==mon_1&&day_2>day_1)
                printf("Case #%ld: 0\n",cas);

            else if(mon_2==mon_1&&day_2==day_1)
                printf("Case #%ld: 1\n",cas);

            else
                printf("Case #%ld: 1\n",cas);

        }

        else if(yr_dif>1&&yr_dif<131)
        {
            if(yr_dif==130)
            {
                if(mon_1>mon_2)
                    printf("Case #%ld: Check birth date\n",cas);

                else
                    printf("Case #%ld: %ld\n",cas,yr_dif);
            }
            else
            {
                if(mon_1<mon_2)
                    printf("Case #%ld: %ld\n",cas,yr_dif-1);

                else if((mon_1==mon_2)&&(day_1<day_2))
                    printf("Case #%ld: %ld\n",cas,yr_dif-1);

                else
                    printf("Case #%ld: %ld\n",cas,yr_dif);
            }

        }

        else if(yr_dif>=131)
        {
            if(yr_dif==131)
            {
                if(mon_1<mon_2)
                    printf("Case #%ld: %ld\n",cas,yr_dif-1);

                else if((mon_1==mon_2)&&(day_1<day_2))
                    printf("Case #%ld: %ld\n",cas,yr_dif-1);

                else
                    printf("Case #%ld: Check birth date\n",cas);

            }
            else
                printf("Case #%ld: Check birth date\n",cas);
        }

    }
    return 0;
}
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: 11219 - How old are you?

Post by sith » Sat Jun 30, 2012 8:07 pm

Hello
Why am I getting WA?
Here is my solution

Code: Select all

import java.io.*;
import java.util.Calendar;
import java.util.Scanner;
import java.util.StringTokenizer;

class Main {


    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));


        try {

            int caseCount = Integer.parseInt(reader.readLine());

            for (int i = 1; i <= caseCount; i++) {
                reader.readLine();
                writer.write("Case #" + i + ": ");
                StringTokenizer tokenizer = new StringTokenizer(reader.readLine(), "/");

                short currentDay = Short.parseShort(tokenizer.nextToken());
                short currentMonth = Short.parseShort(tokenizer.nextToken());
                short currentYear = Short.parseShort(tokenizer.nextToken());

                tokenizer = new StringTokenizer(reader.readLine(), "/");

                short day = Short.parseShort(tokenizer.nextToken());
                short month = Short.parseShort(tokenizer.nextToken());
                short year = Short.parseShort(tokenizer.nextToken());

                Short deltaYear = (short) (currentYear - year);
                short deltaMonth = (short) (currentMonth - month);
                short deltaDay = (short) (currentDay - day);

                if (deltaYear < 0) {
                    writer.write("Invalid birth date\n");
                    continue;
                }

                if (deltaYear == 0 && deltaMonth < 0) {
                    writer.write("Invalid birth date\n");
                    continue;
                }
                if (deltaYear == 0 && deltaMonth == 0 && deltaDay < 0) {
                    writer.write("Invalid birth date\n");
                    continue;
                }
                if (deltaYear > 130) {
                    writer.write("Check birth date\n");
                    continue;
                }

                if (deltaMonth < 0) {
                    deltaYear--;
                }

                if (deltaMonth == 0 && deltaDay < 0) {
                    deltaYear--;
                }


                writer.write(deltaYear.toString());


                writer.write("\n");


            }


            writer.flush();
        } catch (IOException e) {

        }
    }
}

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

Re: 11219 - How old are you?

Post by brianfry713 » Mon Jul 02, 2012 10:22 pm

Input:

Code: Select all

2

01/01/2131
02/01/2000

01/01/2131
01/01/2000
AC output

Code: Select all

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

PromeNabid
New poster
Posts: 21
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.
Contact:

Re: 11219 - How old are you?

Post by PromeNabid » Sat Sep 01, 2012 6:37 pm

Old school age calculation math. Interesting problem. Thanks all for all I/Os. Here is a list of all inputs given in this post, outputs from uvatoolkit.com and my AC code.
Input:

Code: Select all

28

01/01/2004
02/01/2004

02/01/2130
01/01/2000

01/01/2031
02/01/1900

02/02/2031
02/02/1900

01/02/2031
01/02/2031

02/02/2031
03/02/2031

02/02/2031
03/01/2031

29/02/2008
29/02/2000

28/02/2008
29/02/2000

01/03/2008
29/02/2000

01/03/2001
29/02/2000

28/02/2001
29/02/2000

29/02/2000
29/02/2000

29/02/2000
28/02/2000

05/06/2031
06/06/1900

01/02/1984
02/01/1984

12/12/2004
12/12/2003

01/01/2031
02/01/1900

01/02/1984
02/01/1984

01/01/2004
01/02/2004

28/02/2001
10/03/2001

29/02/2000
10/03/2000

02/10/2000
02/11/1999

30/06/1978
08/09/1967

01/03/2000
29/02/2000

19/02/2012
19/03/2010

01/01/2131
02/01/2000

01/01/2131
01/01/2000
OUTPUT:

Code: Select all

Case #1: Invalid birth date
Case #2: 130
Case #3: 130
Case #4: Check birth date
Case #5: 0
Case #6: Invalid birth date
Case #7: 0
Case #8: 8
Case #9: 7
Case #10: 8
Case #11: 1
Case #12: 0
Case #13: 0
Case #14: 0
Case #15: 130
Case #16: 0
Case #17: 1
Case #18: 130
Case #19: 0
Case #20: Invalid birth date
Case #21: Invalid birth date
Case #22: Invalid birth date
Case #23: 0
Case #24: 10
Case #25: 0
Case #26: 1
Case #27: 130
Case #28: Check birth date

dibery
Learning poster
Posts: 76
Joined: Sat Feb 23, 2013 4:16 pm
Location: Taiwan, Taipei
Contact:

Re: 11219 - How old are you?

Post by dibery » Sun Feb 24, 2013 12:04 pm

Hello, I'm having some problems with my code.

Code: Select all

#include<iostream>
using namespace std;

int main()
{
    int by, bm, bd, ey, em, ed, test, age;
    char no;
    cin >> test;

    for( int i = 1; i <= test; ++i )
    {
        cin >> ed >> no >> em >> no >> ey >> bd >> no >> bm >> no >> by;
        age = ey - by;
        if( em < bm || em == bm && ed < bd )
            --age;
        cout << "Case #" << i << ':';
        if( age < 0 )
            cout << " Invalid birth date";
        else if( age > 130 )
            cout << " Check birth date";
        else
            cout << ' ' << age;
        if( i != test )
            cout << endl;
    }
    return 0;
}
What's wrong? Thanks.
Life shouldn't be null.

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

Re: 11219 - How old are you?

Post by brianfry713 » Mon Feb 25, 2013 10:53 pm

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

dibery
Learning poster
Posts: 76
Joined: Sat Feb 23, 2013 4:16 pm
Location: Taiwan, Taipei
Contact:

Re: 11219 - How old are you?

Post by dibery » Tue Feb 26, 2013 7:13 pm

Oh, thanks, brianfry!
I finally got AC...
I've got so many WA on the last line...
But how do you know there should be a new line?
Life shouldn't be null.

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

Re: 11219 - How old are you?

Post by brianfry713 » Wed Feb 27, 2013 1:28 am

Unless the problem states otherwise, always print a newline at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

mobarak.islam
New poster
Posts: 38
Joined: Wed Dec 05, 2012 11:29 pm

Re: 11219 - How old are you?

Post by mobarak.islam » Sun May 19, 2013 5:09 pm

i checked all the input-output for this problem in this forum and got correct answer but i'm getting wa while submitting :(

Code is deleted after getting AC .
Last edited by mobarak.islam on Thu May 23, 2013 10:37 am, edited 1 time in total.

Post Reply

Return to “Volume 112 (11200-11299)”