poj 3393 행운 과 좋 은 달 그 레 고리 안 달력 시 뮬 레이 션

2888 단어 calendarSystemsun
상세 한 분석 은 다음 과 같다.http://www.cnblogs.com/lyy289065406/archive/2011/07/31/2122851.html
#include <stdio.h>
#include <iostream>
using namespace std;
int flagRun=0;
int sum;
int Month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};   //   
int Lmonth[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};  //   
enum week{Sun,Mon,Tue,Wed,Thu,Fri,Sat};  //  

int leap(int year){
     if(year<1582){
         if(year%4==0)
             return 1;
         else return 0;
     }else if(((year%4==0)&&(year%100!=0))||(year%400==0)||(year==1700))
              return 1;
           else
              return 0;
} 
int computeDay(int year,int month){
  int day=1;
  int i;
  for(i=1;i<year;i++){
     if(leap(i))
        day+=366;
     else
         day+=365;   
   }
    for(int j=1;j<month;j++)
         if(leap(i))
            day+=Lmonth[j];
         else
            day+=Month[j];  
    if(year>1752)
        day-=11;
     else if(year==1752 && month>9)
         day-=11; 
     return day;
}
int main(){
    int test;
    cin>>test;
    while(test--){
       int ys,ms,ye,me;
       int *pm;
        int i,j;
        cin>>ys>>ms>>ye>>me;
        int luck=0,good=0;
        int day= computeDay(ys,ms); 
        if(((day+5)%7<=Mon) || ((day+5)%7==Sat))  //    ys ms 1     ,     good month
              good++;                               //1 1 1     ,         ,  +5  
         for(i=ys;i<ye;i++){
                
             if(leap(i))
                pm=Lmonth;
             else 
                pm=Month;
             if(i==ys)
                j=ms;
              else
                 j=1;
             for(;j<13;j++){
                 day+=*(pm+j);
                 if(i==1752&&j==9)
                    day-=11;
                    
                  if(((day+5)%7<=Mon)||((day+5)%7==Sat)){
                      good++;
                      luck++;// j+1 good month, j   luck month                                       
                  }
                                 
             }       
                 
         }   
         
         /*    ye  good,luck month */
         if(leap(i))
           pm=Lmonth;
         else
           pm=Month;
         if(i==ys)// ys=ye
            j=ms;
          else j=1;
          for(;j<=me;j++){
              day+=*(pm+j);
              if(i==1752&&j==9)
                 day-=11;
                 
              if(((day+5)%7<=Mon)||((day+5)%7==Sat)){
                   if(j!=me)   
                      good++;
                      luck++;// j+1 good month, j   luck month                                       
              }
                           
          } 
        cout<<luck<<' '<<good<<endl;
    } 
    system("PAUSE");
    return 0;
}

좋은 웹페이지 즐겨찾기