#14420:


WinstonTsai (我要吉你凸( •̀_•́ )凸)

學校 : 臺北市私立延平高級中學
編號 : 69012
來源 : [203.72.178.252]
最後登入時間 :
2018-12-19 17:14:57
d041. 11219 - How old are you? -- UVa11219 | From: [203.72.178.252] | 發表日期 : 2018-07-16 14:06

d041: 11219 - How old are you? - 高中資訊科技概論教師黃建庭的教學網站

#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;
  }
}

 

 
ZeroJudge Forum