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
-
Shihab
- New poster
- Posts: 33
- Joined: Thu Jun 13, 2013 1:19 pm
Post
by Shihab »
WA , Please Help
Code: Select all
#include<cstdio>
#include<iostream>
using namespace std;
int test_case,age,flag,i=1;
int birth_date,birth_month,current_date,current_month;
int calculate_age();
long long birth_year,current_year;
int main()
{
char slash;
scanf("%d",&test_case);
while(i<=test_case)
{
flag=0;
scanf("%d%c%d%c%lld",¤t_date,&slash,¤t_month,&slash,¤t_year);
scanf("%d%c%d%c%lld",&birth_date,&slash,&birth_month,&slash,&birth_year);
if(current_year<birth_year)
{
printf("Case %d: Invalid birth date",i);
}
else if(current_year==birth_year)
{
if(current_month>=birth_month)
{
if(current_date<=birth_date)
{
age=calculate_age();
flag=1;
}
else
{
printf("Case %d: Invalid birth date",i);
}
}
else
{
printf("Case %d: Invalid birth date",i);
}
}
else
{
flag=1;
age=calculate_age();
if(current_month==birth_month)
{
if(current_date<birth_date)
age--;
}
if(current_month<birth_month)
{
age--;
}
}
if(flag==1)
{
if(age>=130)
printf("Case %d: Check birth date",i);
else
printf("Case %d: %d",i,age);
}
i++;
}
return 0;
}
int calculate_age()
{
return current_year-birth_year;
}
-
brianfry713
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Post
by brianfry713 »
Print a newline char at the end of each line.
Check input and AC output for thousands of problems on
uDebug!
-
Shihab
- New poster
- Posts: 33
- Joined: Thu Jun 13, 2013 1:19 pm
Post
by Shihab »
Why should I ?
Can u tell me the reason.
Still WA
-
brianfry713
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Post
by brianfry713 »
For the sample input, the correct output is:
Code: Select all
Case #1: Invalid birth date
Case #2: Check birth date
Case #3: 23
Case #4: 0
Your output is:
Code: Select all
Case 1: Invalid birth dateCase 2: Check birth dateCase 3: 23Case 4: 0
Your output is wrong. Post your updated code if you're still having trouble.
Check input and AC output for thousands of problems on
uDebug!
-
Shihab
- New poster
- Posts: 33
- Joined: Thu Jun 13, 2013 1:19 pm
Post
by Shihab »
Code Updated
Code: Select all
#include<cstdio>
#include<iostream>
using namespace std;
int test_case,age,flag,i=1;
int birth_date,birth_month,current_date,current_month;
int calculate_age();
long long birth_year,current_year;
int main()
{
char slash;
scanf("%d",&test_case);
while(i<=test_case)
{
flag=0;
scanf("%d%c%d%c%lld",¤t_date,&slash,¤t_month,&slash,¤t_year);
scanf("%d%c%d%c%lld",&birth_date,&slash,&birth_month,&slash,&birth_year);
if(current_year<birth_year)
{
printf("Case #%d: Invalid birth date\n",i);
}
else if(current_year==birth_year)
{
if(current_month>=birth_month)
{
if(current_date<=birth_date)
{
age=calculate_age();
flag=1;
}
else
{
printf("Case #%d: Invalid birth date\n",i);
}
}
else
{
printf("Case #%d: Invalid birth date\n",i);
}
}
else
{
flag=1;
age=calculate_age();
if(current_month==birth_month)
{
if(current_date<birth_date)
age--;
}
if(current_month<birth_month)
{
age--;
}
}
if(flag==1)
{
if(age>=130)
printf("Case #%d: Check birth date\n",i);
else
printf("Case #%d: %d\n",i,age);
}
i++;
}
return 0;
}
int calculate_age()
{
return current_year-birth_year;
}
-
brianfry713
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Post
by brianfry713 »
Check input and AC output for thousands of problems on
uDebug!
-
Shihab
- New poster
- Posts: 33
- Joined: Thu Jun 13, 2013 1:19 pm
Post
by Shihab »
Still WA
-
brianfry713
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Post
by brianfry713 »
The code that you posted is still printing the wrong answer for the input I posted. Post your updated code if you want more help.
Check input and AC output for thousands of problems on
uDebug!
-
Shihab
- New poster
- Posts: 33
- Joined: Thu Jun 13, 2013 1:19 pm
Post
by Shihab »
Code Updated
Code: Select all
#include<cstdio>
#include<iostream>
using namespace std;
int test_case,age,flag,i=1;
int birth_date,birth_month,current_date,current_month;
int calculate_age();
long long birth_year,current_year;
int main()
{
char slash;
scanf("%d",&test_case);
while(i<=test_case)
{
flag=0;
scanf("%d%c%d%c%lld",¤t_date,&slash,¤t_month,&slash,¤t_year);
scanf("%d%c%d%c%lld",&birth_date,&slash,&birth_month,&slash,&birth_year);
if(current_year<birth_year)
{
printf("Case #%d: Invalid birth date\n",i);
}
else if(current_year==birth_year)
{
if(current_month>=birth_month)
{
if(current_date<=birth_date)
{
age=calculate_age();
flag=1;
}
else
{
printf("Case #%d: Invalid birth date\n",i);
}
}
else
{
printf("Case #%d: Invalid birth date\n",i);
}
}
else
{
flag=1;
age=calculate_age();
if(current_month==birth_month)
{
if(current_date<birth_date)
age--;
}
if(current_month<birth_month)
{
age--;
}
}
if(flag==1)
{
if(age>130)
printf("Case #%d: Check birth date\n",i);
else
printf("Case #%d: %d\n",i,age);
}
i++;
}
return 0;
}
int calculate_age()
{
return current_year-birth_year;
}
-
brianfry713
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Post
by brianfry713 »
Check input and AC output for thousands of problems on
uDebug!
-
Shihab
- New poster
- Posts: 33
- Joined: Thu Jun 13, 2013 1:19 pm
Post
by Shihab »
AC , thanks bryanfry
-
Ovro
- New poster
- Posts: 12
- Joined: Mon Nov 11, 2013 8:30 am
Post
by Ovro »
Hello, Getting WA. Can someone tell me why ?
Code: Select all
#include<stdio.h>
int main()
{
int x1,y1,z1,x2,y2,z2,test,i;
long int day,age;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
printf("\n");
scanf("%d/%d/%d",&x1,&y1,&z1);
scanf("%d/%d/%d",&x2,&y2,&z2);
day=(x1+(y1-1)*30+z1*365)-(x2+(y2-1)*30+z2*365);
if(day<0)
printf("Case #%d: Invalid birth date\n",i);
else
{
age=(day-day%365)/365;
if(age>130)
printf("Case #%d: Check birth date\n",i);
else
printf("Case #%d: %ld\n",i,age);
}
}
return 0;
}
-
brianfry713
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Post
by brianfry713 »
The output is comprised of one line for each input data set, don't print extra blank lines.
Check input and AC output for thousands of problems on
uDebug!
-
B_sayem
- New poster
- Posts: 7
- Joined: Wed Dec 11, 2013 7:57 pm
Post
by B_sayem »
Why i got wrong ans??please reply.
Code: Select all
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n,dd1,mm1,yy1,dd2,mm2,yy2,days1,days2,old,check=1;
cin>>n;
while(n>0)
{
cout<<endl;
cin>>dd1;
cin.ignore();
cin>>mm1;
cin.ignore();
cin>>yy1;
days1=(yy1*365)+(mm1*30)+dd1;
cin>>dd2;
cin.ignore();
cin>>mm2;
cin.ignore();
cin>>yy2;
days2=(yy2*365)+(mm2*30)+dd2;
//cout<<endl;
if(days2>days1)
{
cout<<"Case #"<<check<<": "<<"Invalid birth date"<<endl;
}
else
{
old=(days1-days2)/365;
if(old>130)
{
cout<<"Case #"<<check<<": "<<"Check birth date"<<endl;
}
else
cout<<"Case #"<<check<<": "<<old<<endl;
}
check++;
n--;
}
return 0;
}
-
Yousuf
- New poster
- Posts: 13
- Joined: Thu Jun 09, 2011 8:22 am
Post
by Yousuf »
Why you are printing an extra line at the beginning of every test case. You don't need that. Check output format carefully. Hope its helps

.