Advertisement
Eather

February 29

Mar 1st, 2012
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.55 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20. #include <limits>
  21. #include <cstring>
  22. #include <string>
  23. using namespace std;
  24.  
  25. int pel(string s){string t;t=s;reverse(t.begin(),t.end());if(s==t)return 1;return 0;}
  26. string toString(int n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
  27. int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
  28. bool isprime(int m){if(m<2) return 0;for( int i=2; i*i<=m ; i++)if(m%i==0)return 0; return 1;return 0;}
  29.  
  30. # define eps 1e-8
  31. # define inf (1<<30)
  32. # define pi (2*acos(0.0))
  33. # define __(array,w)   memset(array,w,sizeof array)
  34. # define FOR(i, a, b) for (int i=a; i<b; i++)
  35. # define REP(i, a) FOR(i,0,a)
  36. # define all(c) (c).begin(), (c).end()
  37. # define sz(x) x.size()
  38. # define pb push_back
  39. # define UNQ(s) {sort(all(s));(s).erase(unique(all(s)),s.end());}
  40. # define rive(s) reverse(s.begin(),s.end())
  41. # define out(a) cout<<#a<<" #"<<a<<endl;
  42. # define caout(a) cout<<#a<<" "<<++a<<": ";
  43. # define X first
  44. # define Y second
  45. # define MP make_pair
  46. typedef long long LL;
  47. //typedef __int64   LL;
  48. typedef vector<int>vi;
  49. typedef vector<string>vs;
  50. typedef pair<int,int>pri;
  51. typedef map<string,int>msi;
  52. typedef map<vector<int>,int>mvi;
  53. inline bool iseq(double x,double y){if(fabs(x-y)<eps)return true;return false;}
  54. template<typename T>inline double hpt(T x1,T y1,T x2,T y2){return hypot(x1-x2,y1-y2);}
  55. template<typename T>inline T gcd(T a,T b){if(!b)return a;else return gcd(b,a%b);}
  56. template<typename T>inline void extended_euclid(T a,T b,T &x,T &y){if(a%b==0)x=0,y=1;else{extended_euclid(b,a%b,x,y);T temp=x;x=y;y=-y*(a/b)+temp;}}
  57. template<typename T>inline T bigmod(T b,T p,T m){if(!p)return 1;else if(!(p%2)){T x=bigmod(b,p/2,m);return x*x;}else return ((b%m)*bigmod(b,p-1,m))%m;}
  58. #define PS 5
  59. int prime[PS/32+1];
  60. void setbit(int i){int p=i>>5,q=i&31;prime[p]|=(1<<q);}
  61. bool checkbit(int i){int p=i>>5,q=i&31;return prime[p]&(1<<q)?true:false;}
  62. void buildprime(int n){int i,j,k=sqrt(double(n));prime[0]=3;for(i=4;i<n;i+=2)setbit(i);for(i=3;i<=k;i+=2){if(!checkbit(i)){int ii=i+i;for(j=i*i;j<n;j+=ii)setbit(j);}}}
  63.  
  64.  
  65. bool leap(long long n)
  66. {
  67.     if(n%4==0)
  68.     {
  69.         if(n%100==0)
  70.         {
  71.             if(n%400==0)return 1;
  72.         }
  73.         return 1;
  74.     }
  75.     return 0;
  76.  
  77. }
  78. int main()
  79. {
  80. #ifndef ONLINE_JUDGE
  81.     //freopen("in.txt","r",stdin);
  82.     //freopen("out.txt","w",stdout);
  83. #endif
  84.  
  85.     int test,Case=0;
  86.     map<string,int>mp;
  87.     mp["January"]=1;    mp["February"]=2;        mp["March"]=3;    mp["April"]=4;        mp["May"]=5;    mp["June"]=6;        mp["July"]=7;
  88.     mp["August"]=8;    mp["September"]=9;    mp["October"]=10;        mp["November"]=11;    mp["December"]=12;
  89.  
  90.     cin>>test;
  91.  
  92.     while(test--){
  93.     bool f1=0,f2=0;
  94.     string mon1,mon2;
  95.     long long date1,date2,year1,year2;
  96.  
  97.     cin>>mon1;
  98.     scanf("%lld,%lld",&date1,&year1);
  99.  
  100.     cin>>mon2;
  101.     scanf("%lld,%lld",&date2,&year2);
  102.  
  103.     long long res;
  104.     long long a,b;
  105.  
  106.     res= ((year2/4)-((year1-1) /4));
  107.  
  108.     a=((year2/100)-((year1-1)/100));
  109.     b=((year2/400)-((year1-1)/400));
  110.  
  111.     res=res-a+b;
  112.  
  113.  
  114.     if(leap(year1)&& mp[mon1]>2)res--;
  115.     if(leap(year2))
  116.     {
  117.         if(mp[mon2]<2 || (mp[mon2]==2&&date2<29))res--;
  118.     }
  119.  
  120.     printf("Case %d: ",++Case);
  121.     cout<<res<<endl;
  122.     }
  123.  
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement