Code: Select all
1
30/6/1978
8/9/1967
Moderator: Board moderators
Code: Select all
1
30/6/1978
8/9/1967
And why are you printing this extra line?Obaida wrote:Edited but still wA!!!
#include<stdio.h>
.....
scanf("%d",&c);
while(c--)
{
puts("");
count++;
scanf("%d/%d/%d",&d1,&m1,&y1);
.........
}
Each test case starts with a blank line
Obaida wrote:Each test case starts with a blank line
Code: Select all
1
1/3/2000
29/2/2000
Code: Select all
Case #1: 0
Code: Select all
Case #1: Invalid birth date
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
what does it exactly mean ... do i have to do anything special for it....Each test case starts with a blank line
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;
}
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 ...what does it exactly mean ... do i have to do anything special for it....Each test case starts with a blank line
my code is below...
If you take inputs with scanf, you don't need to do anything about it.. So, just ignore itEach test case starts with a blank line
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..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..
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;
}