#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int t, d1, m1, y1, d2, m2, y2, age, cs = 1;
char start[13], finish[13], sd[5], sm[5], sy[5], fd[5], fm[5], fy[5];
cin >> t;
while(t--){
cin >> start >> finish;
sd[0] = start[0];sd[1] = start[1];d1 = sd[0]-48;sd[2] = '\0';
sm[0] = start[3];sm[1] = start[4];m1 = sm[0]-48;sm[2] = '\0';
sy[0] = start[6];sy[1] = start[7];sy[2] = start[8];sy[3] = start[9];y1 = sy[0]-48;sy[4] = '\0';
fd[0] = finish[0];fd[1] = finish[1];d2 = fd[0]-48;fd[2] = '\0';
fm[0] = finish[3];fm[1] = finish[4];m2 = fm[0]-48;fm[2] = '\0';
fy[0] = finish[6];fy[1] = finish[7];fy[2] = finish[8];fy[3] = finish[9];y2 = fy[0]-48;fy[4] = '\0';
d1 = (d1*10) + (sd[1]-48);d2 = (d2*10) + (fd[1]-48);
m1 = (m1*10) + (sm[1]-48);m2 = (m2*10) + (fm[1]-48);
for(int i = 1; i < 4; i++)y1 = (y1*10) + (sy[i]- 48);
for(int i = 1; i < 4; i++)y2 = (y2*10) + (fy[i]- 48);
age = (y1 - y2);
if(m1 < m2)age--;
else if(m1 == m2)if(d1<d2)age--;
if(age < 0)cout << "Case #" << cs << ": Invalid birth date" << endl;
else if(age > 130)cout << "Case #" << cs << ": Check birth date" << endl;
else cout << "Case #" << cs << ": " << age << endl;
cs++;
}
return 0;
}
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int t, d1, m1, y1, d2, m2, y2, age, cs = 1;
char start[13], finish[13], sd[5], sm[5], sy[5], fd[5], fm[5], fy[5];
cin >> t;
while(t--){
cin >> start >> finish;
sd[0] = start[0];sd[1] = start[1];d1 = sd[0]-48;sd[2] = '\0';
sm[0] = start[3];sm[1] = start[4];m1 = sm[0]-48;sm[2] = '\0';
sy[0] = start[6];sy[1] = start[7];sy[2] = start[8];sy[3] = start[9];y1 = sy[0]-48;sy[4] = '\0';
fd[0] = finish[0];fd[1] = finish[1];d2 = fd[0]-48;fd[2] = '\0';
fm[0] = finish[3];fm[1] = finish[4];m2 = fm[0]-48;fm[2] = '\0';
fy[0] = finish[6];fy[1] = finish[7];fy[2] = finish[8];fy[3] = finish[9];y2 = fy[0]-48;fy[4] = '\0';
d1 = (d1*10) + (sd[1]-48);d2 = (d2*10) + (fd[1]-48);
m1 = (m1*10) + (sm[1]-48);m2 = (m2*10) + (fm[1]-48);
for(int i = 1; i < 4; i++)y1 = (y1*10) + (sy[i]- 48);
for(int i = 1; i < 4; i++)y2 = (y2*10) + (fy[i]- 48);
age = (y1 - y2);
if(m1 < m2)age--;
else if(m1 == m2)if(d1<d2)age--;
if(age < 0)cout << "Case #" << cs << ": Invalid birth date" << endl;
else if(age > 130)cout << "Case #" << cs << ": Check birth date" << endl;
else cout << "Case #" << cs << ": " << age << endl;
cs++;
}
return 0;
}
No comments:
Post a Comment