清风竹林

ぷ雪飘绛梅映残红
   ぷ花舞霜飞映苍松
     ----- Do more,suffer less

Friday the Thirteenth


题目:Friday the Thirteenth

简答:


/*
ID: lixianm1
PROG: friday
LANG: C++
*/
#include 
<fstream>
#include 
<iostream>
#include 
<vector>
#include 
<map>
#include 
<string>
#include 
<cassert>

inline 
bool IsLeapYear(unsigned int nYear) {return ((!(nYear&3))&&(0!=nYear%100))||(0==nYear%400);}

int main(int argc, char* argv[]) 
{    
    
//////////////////////////////////////////////////////////////////////////open the file
    std::string strInFile    = "friday.in";
    std::
string strOutFile    = "friday.out";

    std::ifstream fin(strInFile.c_str());
    std::ofstream fout(strOutFile.c_str());

    
if (!fin)
    {
        std::cout
<<"failed to open file for read"<<std::endl;
        
return 1;
    }
    
if (!fout)
    {
        std::cout
<<"failed to open file for write"<<std::endl;
        fin.close();
        
return 1;
    }
    
//////////////////////////////////////////////////////////////////////////read file and init all variables
    

    
int N;
    fin
>>N;

    
//////////////////////////////////////////////////////////////////////////process

    
static int month_day[]={0312831303130313130313031};
    
static int month_day2[]={0312931303130313130313031};

    
int aWeekCount[7]={0};
    unsigned 
int nTotalDays= 0;

    
for (int i=0; i<N; ++i)
    {
        
for (int nMonth=1; nMonth<13++nMonth)
        {
            
++aWeekCount[(nTotalDays+12)%7];
            
            
if (!IsLeapYear(1900+i))
            {
                nTotalDays
+=month_day[nMonth];
            }
else
            {
                nTotalDays
+=month_day2[nMonth];
            }            
        }        
    }
    
    
//////////////////////////////////////////////////////////////////////////write the process result
    for (int i=0; i<6++i)
    {
        fout
<<aWeekCount[(i+5)%7]<<" ";
    }
    fout
<<aWeekCount[4]<<std::endl;

    
//////////////////////////////////////////////////////////////////////////end and exit
    fin.close();
    fout.close();

    
//system("pause");
    return 0;
}

posted on 2008-12-03 14:00 李现民 阅读(262) 评论(0)  编辑 收藏 引用 所属分类: USACO


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理