mhdew

LOJ 1414

Apr 24th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define in() freopen("in.txt", "r", stdin)
  5. #define out() freopen("out.txt", "w", stdout)
  6. char m1[20];
  7. char m2[20];
  8. int d1, d2;
  9. long long y3, y2;
  10.  
  11. int check(long long n)
  12. {
  13.     int flag;
  14.  
  15.     ///If leap, return 1, else return 0
  16.  
  17.     if(n%4==0){
  18.         if(n%100==0){
  19.             if(n%400==0){
  20.                 flag=1;
  21.             }
  22.             else{
  23.                 flag=0;
  24.             }
  25.         }
  26.         else{
  27.             flag=1;
  28.         }
  29.     }
  30.     else{
  31.         flag=0;
  32.     }
  33.  
  34.     return flag;
  35. }
  36.  
  37. int mcheck(char m[])
  38. {
  39.     if(m[0]=='J' && m[1]=='a') return 1;
  40.     else if(m[0]=='F') return 2;
  41.     else if(m[0]=='M' && m[2]=='r') return 3;
  42.     else if(m[0]=='A' && m[2]=='r') return 4;
  43.     else if(m[0]=='M' && m[2]=='y') return 5;
  44.     else if(m[0]=='J' && m[2]=='n') return 6;
  45.     else if(m[0]=='J' && m[2]=='l') return 7;
  46.     else if(m[0]=='A' && m[2]=='g') return 8;
  47.     else if(m[0]=='S') return 9;
  48.     else if(m[0]=='O') return 10;
  49.     else if(m[0]=='N') return 11;
  50.     else if(m[0]=='D') return 12;
  51. }
  52.  
  53. int main()
  54. {
  55.     int t;
  56.     scanf("%d", &t);
  57.     getchar();
  58.     for(int tt=1;tt<=t;tt++){
  59.         int ans=0;
  60.         scanf("%s %d, %lld", m1,&d1,&y3);
  61.         getchar();
  62.         scanf("%s %d, %lld", m2,&d2,&y2);
  63.  
  64.         if(y3==y2){
  65.             if(check(y3)==1){
  66.                 if(mcheck(m1)<=2){
  67.                     if(mcheck(m2)==2){
  68.                         if(d2==29)
  69.                             ans=1;
  70.                     }
  71.                     else if(mcheck(m2)>2){
  72.                         ans=1;
  73.                     }
  74.                 }
  75.             }
  76.             printf("Case %d: %d\n", tt,ans);
  77.             continue;
  78.         }
  79.  
  80.         int x, y, temp;  ///loop range
  81.         temp=y3+1; ///Check x single
  82.         y=y2-1; ///Check y single
  83.  
  84.         for(int i=0;i<8;i++){
  85.             if(check(temp)==1){
  86.                 x=temp;
  87.                 break;
  88.             }
  89.             else{
  90.                 temp++;
  91.             }
  92.         }
  93.  
  94.         if(x==y){
  95.             printf("Case %d: 1\n", tt);
  96.         }
  97.         else if(x>y){
  98.             printf("Case %d: 0\n", tt);
  99.         }
  100.  
  101.         else{
  102.             int cunt=0;
  103.             int dif=y2-y3;
  104.  
  105.             cunt=dif/4+dif/400-dif/100;
  106.  
  107.             if(check(y3)==1){
  108.                 if(mcheck(m1)<=2){
  109.                     cunt++;
  110.                 }
  111.             }
  112.  
  113.             if(check(y2)==1){
  114.                 if(mcheck(m2)==2){
  115.                     if(d2<29){
  116.                         cunt--;
  117.                     }
  118.                 }
  119.                 else if(mcheck(m2)==1){
  120.                     cunt++;
  121.                 }
  122.             }
  123.  
  124.             printf("Case %d: %d\n", tt, cunt);
  125.         }
  126.  
  127.     }
  128.  
  129.     return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment