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

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

Re: 11219 - How old are you?

Post by newkid » Sat Jan 10, 2009 11:06 am

try this..

Code: Select all

1
30/6/1978
8/9/1967
it should print 10. but your code prints 11.
hmm..

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

Re: 11219 - How old are you?

Post by newkid » Sat Jan 10, 2009 11:11 am

Obaida wrote:Edited but still wA!!!
#include<stdio.h>
.....
scanf("%d",&c);
while(c--)
{
puts("");
count++;
scanf("%d/%d/%d",&d1,&m1,&y1);
.........
}
And why are you printing this extra line?
hmm..

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 11219 - How old are you?

Post by Obaida » Sat Jan 10, 2009 12:28 pm

Each test case starts with a blank line
:D
try_try_try_try_&&&_try@try.com
This may be the address of success.

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

Re: 11219 - How old are you?

Post by newkid » Sat Jan 10, 2009 12:57 pm

Thats my friend is the description of the INPUT.. not the OUTPUT.. read the problem statements again..
Obaida wrote:
Each test case starts with a blank line
:D
:D :D
hmm..

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 11219 - How old are you?

Post by Obaida » Sat Jan 17, 2009 11:23 am

Thanks when i concentrated deeply.. I got Acc.
thank you for clearing me. :D
try_try_try_try_&&&_try@try.com
This may be the address of success.

aliahmed
New poster
Posts: 24
Joined: Fri Oct 24, 2008 8:37 pm
Location: CUET, Chittagong, Bangladesh
Contact:

Re: 11219 - How old are you?

Post by aliahmed » Wed Mar 25, 2009 4:51 pm

What' s wrong with my code. getting WA

#include<stdio.h>
#include<math.h>
#include<string.h>

int main()
{
long dd, mm, yy, dd1, mm1, yy1, i, j, n, l, f, c=1;
char str[20],str1[20];

scanf("%ld",&n);
getchar();
while(n>0)
{
dd=0; mm=0; yy=0;
dd1=0; mm1=0; yy1=0;
scanf("%s %s",&str, &str1);
l=strlen(str);

/////////////integer convert
for(i=0; i<l; i++)
{
if(i<2)
{
dd=dd*10+str-48;
//printf("%ld\n",dd);
continue;
}
else if(i>2 && i<5)
{
mm=mm*10+str-48;
continue;
}
else if(i>5 && i<10)
{
yy=yy*10+str-48;
}
}

l=strlen(str1);
for(i=0; i<l; i++)
{
if(i<2)
{
dd1=dd1*10+str1-48;
continue;
}
else if(i>2 && i<5)
{
mm1=mm1*10+str1-48;
continue;
}
else if(i>5 && i<10)
{
yy1=yy1*10+str1-48;
}
}

f=0;

if(yy>yy1)
{
f=0;
}
else if(yy==yy1)
{
if(mm>mm1)
f=0;
else if(mm==mm1)
{
if(dd>=dd1)
f=0;
else if(dd<dd1)
f=1;
}
else
{
f=1;
}
}
else
f=1;



///////////printing output

printf("Case #%ld: ",c++);
if(f==1)
printf("Invalid birth date\n");
else if((yy-yy1)>130)
printf("Check birth date\n");
else if(mm>mm1)
printf("%ld\n",yy-yy1);
else if(mm<mm1)
printf("%ld\n",yy-yy1-1);
else if(mm==mm1)
{
if(dd>dd1)
printf("%ld\n",yy-yy1);
else if(dd==dd1)
printf("%ld\n",yy-yy1);
else
printf("%ld\n",yy-yy1-1);
}
n--;
}
return 0;
}

User avatar
kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 11219 - How old are you?

Post by kbr_iut » Fri Apr 03, 2009 7:37 pm

try this

input:

Code: Select all

1
1/3/2000
29/2/2000
output:

Code: Select all

Case #1: 0
ur code gives

Code: Select all

Case #1: Invalid birth date
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

sharath
New poster
Posts: 6
Joined: Tue Sep 16, 2008 9:21 pm

Re: 11219 - How old are you?

Post by sharath » Thu Jun 11, 2009 7:52 am

#include <stdio.h>

int main ()
{
int num_test, i, td_date, td_mnth, td_year;
int bd_date, bd_mnth, bd_year, days;

scanf ("%d", &num_test);

for (i = 1; i <= num_test; i ++)
{
scanf ("%d/%d/%d", &td_date, &td_mnth, &td_year);
scanf ("%d/%d/%d", &bd_date, &bd_mnth, &bd_year);

days = (td_year - bd_year) * 365;
days += ((td_mnth - bd_mnth) * 31);
days += (td_date - bd_date);

if (days < 0)
{
printf ("Case #%d: Invalid birth date\n", i);
continue;
}

days /= 365;
if (days > 130)
{
printf ("Case #%d: Check birth date\n", i);
continue;
}
else
{
printf ("Case #%d: %d\n", i, days);
}
}
return 0;
}

I am getting WA for this....I checked with all cases listed in this thread yet WA....please help...

layesh
New poster
Posts: 5
Joined: Wed Jun 10, 2009 10:13 pm

11219 need some critical input........

Post by layesh » Sat Aug 08, 2009 9:42 pm

here is my code

#include<stdio.h>
#include<string.h>

int main()
{
int lens1,lens2,i,j,k,l,m,m1,n,p,q,r,d,d1,y,y1,t,flag,fac;
char s1[2000];
char s2[2000];
freopen("11219.txt","r",stdin);
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Case #%d: ",i+1);
d=d1=m=m1=y=y1=0;
scanf("%s",&s1);
lens1=strlen(s1);
scanf("%s",&s2);
lens2=strlen(s2);
flag=0;
fac=1;
p=lens1-1;
while(flag==0){
if(s1[p]=='/')break;
t=(int(s1[p])-48)*fac;
y+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(s1[p]=='/')break;
t=(int(s1[p])-48)*fac;
m+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(p<0)break;
t=(int(s1[p])-48)*fac;
d+=t;
fac=fac*10;
p--;
}
fac=1;
p=lens2-1;
while(flag==0){
if(s2[p]=='/')break;
t=(int(s2[p])-48)*fac;
y1+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(s2[p]=='/')break;
t=(int(s2[p])-48)*fac;
m1+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(p<0)break;
t=(int(s2[p])-48)*fac;
d1+=t;
fac=fac*10;
p--;
}
j=d-d1;
k=m-m1;
l=y-y1;

if(l>=1 && l<=130){
if(k<0)printf("%d\n",l-1);
else if(k==0 && j<0)printf("%d\n",l-1);
else printf("%d\n",l);

}
else if(l==0){
if(k==0 && j<0)printf("Invalid birth date\n");
else if(k>0)printf("%d\n",l);
else printf("Invalid birth date\n");
}
else if(l>130){
if(k<0)printf("%d\n",l-1);
else if(k==0 && j<0)printf("%d\n",l-1);
else printf("Check birth date\n");
}
}
return 0;
}

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 11219 - How old are you?

Post by sazzadcsedu » Sat Aug 08, 2009 10:32 pm

Sample IO:
2

31/11/2005
01/12/1870

31/11/2002
01/12/1870


your program says
Case #1: 134
Case #2: 131

But my accepted program says

Case #1: Check birth date
Case #2: Check birth date
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

layesh
New poster
Posts: 5
Joined: Wed Jun 10, 2009 10:13 pm

Re: 11219 - How old are you?

Post by layesh » Fri Aug 21, 2009 9:18 pm

thanks.but i still getting WA.
plz check this one

#include<stdio.h>
#include<string.h>

int main()
{
int lens1,lens2,i,j,k,l,m,m1,n,p,q,r,d,d1,y,y1,t,flag,fac;
char s1[2000];
char s2[2000];
freopen("11219.txt","r",stdin);
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Case #%d: ",i+1);
d=d1=m=m1=y=y1=0;
scanf("%s",&s1);
lens1=strlen(s1);
scanf("%s",&s2);
lens2=strlen(s2);
flag=0;
fac=1;
p=lens1-1;
while(flag==0){
if(s1[p]=='/')break;
t=(int(s1[p])-48)*fac;
y+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(s1[p]=='/')break;
t=(int(s1[p])-48)*fac;
m+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(p<0)break;
t=(int(s1[p])-48)*fac;
d+=t;
fac=fac*10;
p--;
}
fac=1;
p=lens2-1;
while(flag==0){
if(s2[p]=='/')break;
t=(int(s2[p])-48)*fac;
y1+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(s2[p]=='/')break;
t=(int(s2[p])-48)*fac;
m1+=t;
fac=fac*10;
p--;
}
fac=1;
p--;
while(flag==0){
if(p<0)break;
t=(int(s2[p])-48)*fac;
d1+=t;
fac=fac*10;
p--;
}
j=d-d1;
k=m-m1;
l=y-y1;

if(l>=1 && l<=130){
if(k<0)printf("%d\n",l-1);
else if(k==0 && j<0)printf("%d\n",l-1);
else printf("%d\n",l);

}
else if(l==0){
if(k==0 && j<0)printf("Invalid birth date\n");
else if(k>0)printf("%d\n",l);
else if(k>=0 && j>=0)printf("%d\n",l);
else printf("Invalid birth date\n");
}
else if(l>130){
if(k<0 && l==131)printf("%d\n",l-1);
else if(k==0 && j<0 && l==131)printf("%d\n",l-1);
else printf("Check birth date\n");
}
}
return 0;
}

mehrab
New poster
Posts: 10
Joined: Sat Jul 03, 2010 3:04 pm

Re: 11219 - How old are you?

Post by mehrab » Thu Aug 05, 2010 3:45 pm

i don't know why am i getting wrong answer for this code...i am getting correct answer for all the given inputs in the forum....what's my fault then....

and there's a line in the question ...
Each test case starts with a blank line
what does it exactly mean ... do i have to do anything special for it....

my code is below...

Code: Select all

#include <stdio.h>

int main()
{
	int date1,month1,year1,date2,month2,year2,cas,i;
	long int days;
	scanf("%d",&cas);
	
	for(i=0;i<cas;i++)
	{
	
		scanf("%d/%d/%d",&date1,&month1,&year1);
		scanf("%d/%d/%d",&date2,&month2,&year2);
	
		days=((date1-date2)+(month1-month2)*31+(year1-year2)*365);
		
		if(days<0)
			printf("Case #%d: Invalid birth date\n",i+1);
		days/=365;
		if(days>130)
			printf("Case #%d: Check birth date\n",i+1);
		else
			printf("Case #%d: %ld\n",i+1,days/365);
	}
	return 0;
}

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 11219 - How old are you?

Post by helloneo » Thu Aug 05, 2010 5:43 pm

mehrab wrote:i don't know why am i getting wrong answer for this code...i am getting correct answer for all the given inputs in the forum....what's my fault then....

and there's a line in the question ...
Each test case starts with a blank line
what does it exactly mean ... do i have to do anything special for it....

my code is below...
Each test case starts with a blank line
If you take inputs with scanf, you don't need to do anything about it.. So, just ignore it :)

Your calculation and the way printing output is all wrong..
Read the previous posts and try test cases on it. Your code fails on most of them..

mehrab
New poster
Posts: 10
Joined: Sat Jul 03, 2010 3:04 pm

Re: 11219 - How old are you?

Post by mehrab » Fri Sep 10, 2010 1:17 pm

Your calculation and the way printing output is all wrong..
Read the previous posts and try test cases on it. Your code fails on most of them..
i did a silly mistake in the logic but still it is getting wrong answer though it is matching the output with all the test inputs given..
:(
would you please check it for me ... thnx

Code: Select all

#include <stdio.h>
#include <math.h>

int main()
{
   int date1,month1,year1,date2,month2,year2,cas,i;
   double days;
   scanf("%d",&cas);
   for(i=0;i<cas;i++)
   {
   
      scanf("%d/%d/%d",&date1,&month1,&year1);
      scanf("%d/%d/%d",&date2,&month2,&year2);
   
      days=((date1-date2)+(month1-month2)*31+(year1-year2)*365);
      
      if(days<0)
	  {
		  printf("Case #%d: Invalid birth date\n",i+1);
		  continue;
	  }
      days=floor(days/365);
      if(days>130)
         printf("Case #%d: Check birth date\n",i+1);
      else
         printf("Case #%d: %.0lf\n",i+1,days+1e-6);
   }
   return 0;
}

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:30 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;

}

Post Reply

Return to “Volume 112 (11200-11299)”