11219 - How old are you?
Moderator: Board moderators
Re: [11219 - How old are you?] Wrong Answer!! Plz help me
HELP!! Keeps getting Wrong Answer!!
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);
}
}
}
}
}
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);
}
}
}
}
}
Re: [11219 - How old are you?] Wrong Answer!! Plz help me
Can anyone post some sample test cases? That would be helpful! ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
-
- 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!
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
![:)](./images/smilies/icon_smile.gif)
-
- 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!
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:
AC Output:
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
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
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.
Re: [11219 - How old are you?] Wrong Answer!! Plz help me
Try this
Output
Don't forget to remove your code after getting accepted. ![8)](./images/smilies/icon_cool.gif)
Code: Select all
1
01/10/2007
10/01/2007
Code: Select all
Case #1: 0
![8)](./images/smilies/icon_cool.gif)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: [11219 - How old are you?] Wrong Answer!! Plz help me
Thanks I got AC...
![:D](./images/smilies/icon_biggrin.gif)
![:D](./images/smilies/icon_biggrin.gif)
![:D](./images/smilies/icon_biggrin.gif)
-
- 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.
Could someone please help me?
thanks in advance
Could someone please help me?
thanks in advance
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.
Re: 11219 - How old are you?
Input
Acc Output
Don't forget to remove your code after getting accepted. ![8)](./images/smilies/icon_cool.gif)
Code: Select all
1
01/01/2015
31/12/2014
Code: Select all
Case #1: 0
![8)](./images/smilies/icon_cool.gif)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- New poster
- Posts: 2
- Joined: Sun Nov 09, 2014 8:02 pm
Re: 11219 - How old are you?
Thanks got finally accepted ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
-
- 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
thanks in advance
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
![:D](./images/smilies/icon_biggrin.gif)
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;
}