#include <iostream>
#include <sstream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string s1,s2;
int n,d1,d2,m1,m2,y1,y2,ncase=1;
cin >> n;
for(int k=0;k<n;k++){
cin >>s1 >> s2;
d1=0,d2=0,m1=0,m2=0,y1=0,y2=0;
d1=(s1[0]-'0')*10+(s1[1]-'0');
d2=(s2[0]-'0')*10+(s2[1]-'0');
m1=(s1[3]-'0')*10+(s1[4]-'0');
m2=(s2[3]-'0')*10+(s2[4]-'0');
y1=(s1[6]-'0')*1000+(s1[7]-'0')*100+(s1[8]-'0')*10+(s1[9]-'0');
y2=(s2[6]-'0')*1000+(s2[7]-'0')*100+(s2[8]-'0')*10+(s2[9]-'0');
cout <<"Case #"<<ncase++<<": ";
if (y1<y2) cout <<"Invalid birth date"<<endl;
else if ((y1==y2)&&(m1<m2)) cout <<"Invalid birth date"<<endl;
else if ((y1==y2)&&(m1==m2)&&(d1<d2)) cout <<"Invalid birth date"<<endl;
else if ((y1==y2)&&((m1==m2)||(d1>=d2))) cout <<0<<endl;
else if ((y1==y2)&&(m1>m2)) cout << 0 <<endl;
else if ((y1-y2)>131) cout <<"Check birth date"<<endl;
else if (((y1-y2)==131)&&(m1>m2)) cout <<"Check birth date"<<endl;
else if (((y1-y2)==131)&&(m1==m2)&&(d1>=d2)) cout <<"Check birth date"<<endl;
else if (m1<m2) cout << y1-y2-1<<endl;
else if ((m1==m2)&&(d1<d2)) cout << y1-y2-1<<endl;
else cout << y1-y2<<endl;
}
}
|