## 11219 - How old are you?

Moderator: Board moderators

jaime21
New poster
Posts: 6
Joined: Wed Apr 09, 2014 4:36 pm

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

import java.util.*;

class Main{

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int i, tc, m1=0, m2=0, d1=0, d2=0, y1=0, y2=0, age=0;
String input, input2;
String[] numbers, numbers2;

tc = sc.nextInt();
sc.nextLine();
for(i=1; i<=tc; i++){
System.out.println();
input = sc.nextLine();
sc.nextLine();
input2 = sc.nextLine();

if( input.isEmpty() || input2.isEmpty() ){
System.out.format("Case #%d: Invalid birth date\n",i);
}

else{
numbers = input.split("/");
numbers2 = input2.split("/");

if(numbers.length==3 && numbers2.length==3){
d1 = Integer.parseInt(numbers[0]);
m1 = Integer.parseInt(numbers[1]);
y1 = Integer.parseInt(numbers[2]);

d2 = Integer.parseInt(numbers2[0]);
m2 = Integer.parseInt(numbers2[1]);
y2 = Integer.parseInt(numbers2[2]);
}

if( y2>y1 || (y2==y1 && m2>m1) || (y2==y1 && m2==m1 && d2>d1) ){
System.out.format("Case #%d: Invalid birth date\n", i);
}
else if( y1-y2 > 130 ){
System.out.format("Case #%d: Check birth date\n",i);
}
else{
age = y1-y2;
if( m2>m1 || (m2==m1 && d2>d1) )
age--;
if(age<0)
age = 0;
System.out.format("Case #%d: %d\n", i, age);
}
}
}

}

}

jaime21
New poster
Posts: 6
Joined: Wed Apr 09, 2014 4:36 pm

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

Can anyone post some sample test cases? That would be helpful!

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

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

jaime21
New poster
Posts: 6
Joined: Wed Apr 09, 2014 4:36 pm

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

@brianfry713 i ran it with the sample input, and the output is correct! Help please. I have an exam tomorrow

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

Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

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

Here's some input / output I found useful during testing / debugging.

Note that this test case is inclusive of the one given in the problem statement.

Input:

Code: Select all

``````12

01/01/2007
10/02/2007

09/06/2007
28/02/1871

12/11/2007
01/01/1984

28/02/2005
29/02/2004

28/08/2012
28/08/2012

30/04/1931
29/06/1930

03/04/1776
06/04/1775

06/04/1776
05/04/1775

06/04/1776
07/04/1775

05/05/1130
05/06/1000

05/05/1130
04/05/1000

04/05/1130
04/05/1000
``````
AC Output:

Code: Select all

``````Case #1: Invalid birth date
Case #2: Check birth date
Case #3: 23
Case #4: 0
Case #5: 0
Case #6: 0
Case #7: 0
Case #8: 1
Case #9: 0
Case #10: 129
Case #11: 130
Case #12: 130``````
Check input and AC output for over 7,500 problems on uDebug!

axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

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

I've tested the input/outputs by v1n1t but still getting WA. Plz help....

Code: Select all

``Removed after AC``
Last edited by axelblaze on Mon Aug 11, 2014 10:30 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

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

Try this

Code: Select all

``````1

01/10/2007
10/01/2007``````
Output

Code: Select all

``Case #1: 0``
Don't forget to remove your code after getting accepted.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

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

Thanks I got AC...

Sercan Eren
New poster
Posts: 2
Joined: Sun Nov 09, 2014 8:02 pm

### Re: 11219 - How old are you?

Hi, I have tested all test cases which where posted in this thread and I always got the right output but unfortunately I still get WA when I upload my code.

Code: Select all

``````got AC :)
thanks once again for your fast help ^^``````
Last edited by Sercan Eren on Mon Nov 10, 2014 5:20 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 11219 - How old are you?

Input

Code: Select all

``````1

01/01/2015
31/12/2014``````
Acc Output

Code: Select all

``Case #1: 0``
Don't forget to remove your code after getting accepted.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Sercan Eren
New poster
Posts: 2
Joined: Sun Nov 09, 2014 8:02 pm

### Re: 11219 - How old are you?

Thanks got finally accepted

tareksaleh96
New poster
Posts: 1
Joined: Wed Jan 20, 2016 1:09 pm

### Re: 11219 - How old are you?

Hi,
I have been trying all the test cases here and still getting WA, now it got really frustrating
here is my code, i'd appreciate any and all helo

Code: Select all

``````/*
From UVA "https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2489"
*/
#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
int T;
int d1, d2, m1, m2, y1, y2;
vector<int> sols;
scanf("%d", &T);
while (T--)
{
scanf("%d/%d/%d", &d1, &m1, &y1);
scanf("%d/%d/%d", &d2, &m2, &y2);
//cout << d1 << " " << m1 << " " << y1 << endl << d2 << " " << m2 << " " << y2 << endl;
if (y1 == y2)
{
if (m1 == m2)
{
if (d1 >= d2)
{
sols.push_back(0);
}
else
{
sols.push_back(-1);
}
}
else if (m1 > m2)
{
sols.push_back(0);
}
else
{
sols.push_back(-1);
}
}
else if (y1 > y2)
{
if (m1 == m2)
{
if (d1 >= d2)
{
if (y1 - y2 > 130)
{
sols.push_back(-2);
}
else
{
sols.push_back(y1 - y2);
}
}
else {
if (y1 - y2-1 > 130)
{
sols.push_back(-2);
}
else
{
sols.push_back(y1 - y2 - 1);
}
}
}
else if (m1 > m2)
{
if (y1 - y2 > 130)
{
sols.push_back(-2);
}
else
{
sols.push_back(y1 - y2);
}
}
else
{
if (y1 - y2-1 > 130)
{
sols.push_back(-2);
}
else
{
sols.push_back(y1 - y2 - 1);
}
}
}
}
for (int i = 0, len = sols.size(); i < len; i++)
{
if (sols[i] == -1)
{
printf("Case #%d: Invalid birth date\n", i+1);
}
else if (sols[i] == -2)
{
printf("Case #%d: Check birth date\n", i+1);
}
else
{
printf("Case #%d: %d\n", i+1, sols[i]);
}
}
//system("pause");
return 0;
}

``````