UVA 11219 Solution
Solve in C:
#include<stdio.h>
int main()
{
char s1,s2,s3,t1,t2,t3;
int d1,d2,m1,m2,y1,y2,n,i,age;
double year;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d%c%d%c%d%c",&d1,&s1,&m1,&s2,&y1,&s3);
scanf("%d%c%d%c%d%c",&d2,&t1,&m2,&t2,&y2,&t3);
{
if(y1<y2)
printf("Case #%d: Invalid birth date\n",i);
else if(y1==y2)
{
if( m1<m2)
printf("Case #%d: Invalid birth date\n",i);
else if(m1==m2&&d2>d1)
printf("Case #%d: Invalid birth date\n",i);
else if(m1==m2&&d2<d1)
printf("Case #%d: 0\n",i);
else if(m1>m2&&d2>d1)
printf("Case #%d: 0\n",i);
else if(m1>m2&&d1==d2)
printf("Case #%d: 0\n",i);
else if(m1>m2&&d1>d2)
printf("Case #%d: 0\n",i);
else if(m1==m2&&d2==d1)
printf("Case #%d: 0\n",i);
}
else if(y1>y2)
{
if(m1>m2&&d1>d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else
{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1>m2&&d1==d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1>m2&&d1<d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1<m2&&d1>d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1<m2&&d1<d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1<m2&&d1==d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1==m2&&d1==d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1==m2&&d1>d2)
{
age=((y1-y2)*365)+((m1-m2)*30)+(d2-d1);
year=(float)age/365.0;
{
printf("%lf",year);
if(year>130.000000000)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year+1;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1==m2&&d1<d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=((float)age/365);
{
if(year>131.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
}
}
}
}
#include<stdio.h>
int main()
{
char s1,s2,s3,t1,t2,t3;
int d1,d2,m1,m2,y1,y2,n,i,age;
double year;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%d%c%d%c%d%c",&d1,&s1,&m1,&s2,&y1,&s3);
scanf("%d%c%d%c%d%c",&d2,&t1,&m2,&t2,&y2,&t3);
{
if(y1<y2)
printf("Case #%d: Invalid birth date\n",i);
else if(y1==y2)
{
if( m1<m2)
printf("Case #%d: Invalid birth date\n",i);
else if(m1==m2&&d2>d1)
printf("Case #%d: Invalid birth date\n",i);
else if(m1==m2&&d2<d1)
printf("Case #%d: 0\n",i);
else if(m1>m2&&d2>d1)
printf("Case #%d: 0\n",i);
else if(m1>m2&&d1==d2)
printf("Case #%d: 0\n",i);
else if(m1>m2&&d1>d2)
printf("Case #%d: 0\n",i);
else if(m1==m2&&d2==d1)
printf("Case #%d: 0\n",i);
}
else if(y1>y2)
{
if(m1>m2&&d1>d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else
{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1>m2&&d1==d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1>m2&&d1<d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1<m2&&d1>d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1<m2&&d1<d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1<m2&&d1==d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1==m2&&d1==d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=(float)age/365;
{
if(year>130.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1==m2&&d1>d2)
{
age=((y1-y2)*365)+((m1-m2)*30)+(d2-d1);
year=(float)age/365.0;
{
printf("%lf",year);
if(year>130.000000000)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year+1;
printf("Case #%d: %ld\n",i,yr);
}
}
}
else if(m1==m2&&d1<d2)
{
age=(y1-y2)*365+(m1-m2)*30+(d1-d2)*1;
year=((float)age/365);
{
if(year>131.0)
printf("Case #%d: Check birth date\n",i);
else{
long yr=year;
printf("Case #%d: %ld\n",i,yr);
}
}
}
}
}
}
}
No comments