Page 4 of 8

Re: 11219 - How old are you?

Posted: Sat Jan 10, 2009 11:06 am
by newkid
try this..

Code: Select all

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

Re: 11219 - How old are you?

Posted: Sat Jan 10, 2009 11:11 am
by newkid
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?

Re: 11219 - How old are you?

Posted: Sat Jan 10, 2009 12:28 pm
by Obaida
Each test case starts with a blank line
:D

Re: 11219 - How old are you?

Posted: Sat Jan 10, 2009 12:57 pm
by newkid
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

Re: 11219 - How old are you?

Posted: Sat Jan 17, 2009 11:23 am
by Obaida
Thanks when i concentrated deeply.. I got Acc.
thank you for clearing me. :D

Re: 11219 - How old are you?

Posted: Wed Mar 25, 2009 4:51 pm
by aliahmed
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;
}

Re: 11219 - How old are you?

Posted: Fri Apr 03, 2009 7:37 pm
by kbr_iut
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

Re: 11219 - How old are you?

Posted: Thu Jun 11, 2009 7:52 am
by sharath
#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...

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

Posted: Sat Aug 08, 2009 9:42 pm
by layesh
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;
}

Re: 11219 - How old are you?

Posted: Sat Aug 08, 2009 10:32 pm
by sazzadcsedu
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

Re: 11219 - How old are you?

Posted: Fri Aug 21, 2009 9:18 pm
by layesh
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;
}

Re: 11219 - How old are you?

Posted: Thu Aug 05, 2010 3:45 pm
by mehrab
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;
}

Re: 11219 - How old are you?

Posted: Thu Aug 05, 2010 5:43 pm
by helloneo
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..

Re: 11219 - How old are you?

Posted: Fri Sep 10, 2010 1:17 pm
by mehrab
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;
}

Re: 11219 - How old are you/

Posted: Mon May 23, 2011 1:30 pm
by rahat khan
#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;

}