六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 44|回复: 0

USACO:Section 1.1 Friday the Thirteenth

[复制链接]

升级  85%

884

主题

884

主题

884

主题

探花

Rank: 6Rank: 6

积分
2700
 楼主| 发表于 2013-1-26 13:45:39 | 显示全部楼层 |阅读模式
/*ID:lwj13961 TASK:fridayLANG: C++*/#include<iostream>#include<fstream>#include<cassert>using namespace std;bool isleapyear(int year){if(year%100!=0&&year%4==0) return true;if(year%100==0&&year%400==0) return true;return false;}int main(){int N;int fre[7]={0};int normalyear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};int leapyear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};    int *pyear; int days=0;//////////////////////////////////////get input char *ifs_file_name = "friday.in";/* input  file name       */ifstreamifs;/* create ifstream object */ifs.open (ifs_file_name);/* open ifstream          */if (!ifs) {cerr << "\nERROR : failed to open input  file " << ifs_file_name << endl;exit (EXIT_FAILURE);}ifs>>N;assert(N>=0&&N<=400);ifs.close ();/* close ifstream         *///////////////////////////////////////for(int i=0;i<N;i++){if(isleapyear(1900+i)){pyear=leapyear;cout<<1900+i<<" 闰年 "; }elsepyear=normalyear;for(int j=0;j<12;j++){int t;if(j>0){days += pyear[j-1];t=(days+13)%7;}else{if(i>0)days += 31;t=(days+13)%7;}fre[t]++;//cout<<1900+i<<"年 "<<j+1<<" 月13号是星期"<<t<<endl;}}//////////////////////////////////////make ouputchar *ofs_file_name = "friday.out";/* output file name       */ofstreamofs;/* create ofstream object */ofs.open (ofs_file_name);/* open ofstream          */if (!ofs) {cerr << "\nERROR : failed to open output file " << ofs_file_name << endl;exit (EXIT_FAILURE);}ofs<<fre[6];for(int i=0;i<6;i++)ofs<<" "<<fre[i]; ofs<<endl;ofs.close ();/* close ofstream         *///////////////////////////////////////getchar();getchar();return 0;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表