problem link-click here
accepted code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m,d,y,m1,d1,y1,t,i,s;
while(scanf("%d",&t)==1)
{
i=1;
while(t>=i)
{
scanf("%d/%d/%d",&d,&m,&y);
scanf("%d/%d/%d",&d1,&m1,&y1);
s=y-y1;
if(m1>m)
{
s--;
}
else if(m==m1)
{
if(d1>d)
{
s--;
}
}
if(s<0)
{
printf("Case #%d: Invalid birth date\n",i);
}
else if(s>130)
{
printf("Case #%d: Check birth date\n",i);
}
else
{
printf("Case #%d: %d\n",i,s);
}
i++;
}
}
return 0;
}
accepted code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m,d,y,m1,d1,y1,t,i,s;
while(scanf("%d",&t)==1)
{
i=1;
while(t>=i)
{
scanf("%d/%d/%d",&d,&m,&y);
scanf("%d/%d/%d",&d1,&m1,&y1);
s=y-y1;
if(m1>m)
{
s--;
}
else if(m==m1)
{
if(d1>d)
{
s--;
}
}
if(s<0)
{
printf("Case #%d: Invalid birth date\n",i);
}
else if(s>130)
{
printf("Case #%d: Check birth date\n",i);
}
else
{
printf("Case #%d: %d\n",i,s);
}
i++;
}
}
return 0;
}
No comments:
Post a Comment