关于日期的处理 usaco Friday the Thirteeth
来源:互联网 发布:基于单片机的智能床 编辑:程序博客网 时间:2024/06/14 14:36
关于日期的处理无非是要正确处理闰年和闰月的问题。今天所做的那个题
是这样的,告诉你1900年的1月1日是星期一,问从这天起到以后1900+N-1的12
月31日为止,每一个月的十三号分别落在一个星期内每一天中的的次数。刚做这
道题的时候,我先计算从第一天到最后一天的所有的天数,然后再来推13号落在
星期几上。其实这是完全没有必要的,因为在算完所有的天数以后,我还是得要
从第一个月开始,一个月一个月的推,由于相邻的两个月的13号这间恰好相差一
个月的时间,所以规律很明显就出来了。
具体代码如下:
是这样的,告诉你1900年的1月1日是星期一,问从这天起到以后1900+N-1的12
月31日为止,每一个月的十三号分别落在一个星期内每一天中的的次数。刚做这
道题的时候,我先计算从第一天到最后一天的所有的天数,然后再来推13号落在
星期几上。其实这是完全没有必要的,因为在算完所有的天数以后,我还是得要
从第一个月开始,一个月一个月的推,由于相邻的两个月的13号这间恰好相差一
个月的时间,所以规律很明显就出来了。
具体代码如下:
- /*
- ID:zhangwenjun32
- PROG:friday
- LANG:C++
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int N;
- int an[7];
- int loopyear(int year)
- {
- if((year%4==0&&year%100!=0)||year%400==0) return 366;
- else return 365;
- }
- int ismonth(int month,int year)
- {
- switch(month)
- {
- case 2:if(loopyear(year)==366) return 29;
- else return 28;
- case 4:
- case 6:
- case 9:
- case 11:return 30;
- default:return 31;
- }
- }
- int main()
- {
- ifstream fin("friday.in");
- ofstream fout("friday.out");
- fin>>N;
- memset(an,0,sizeof(an));
- int year = 1900;
- int flag=0;
- flag = (an[0]+12)%7;
- an[flag]++;
- for(int i=0;i<N;++i)
- {
- //sumdays+=loopyear(year+i);
- for(int j=1;j<=12;++j)
- {
- int m_days = ismonth(j,year+i);
- flag = (flag+m_days)%7;
- an[flag]++;
- //cout<<month<<" "<<m_days<<" "<<flag<<endl;
- //cout<<month<<endl;
- m_days = ismonth(j,year+i);
- }
- }
- an[flag]--;
- int k=5;
- for(int i=0;i<7;++i)
- {
- if(i==0)
- fout<<an[k];
- else fout<<" "<<an[k];
- k = (k+1)%7;
- }
- fout<<endl;
- return 0;
- }
- 关于日期的处理 usaco Friday the Thirteeth
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth[日期]
- Friday the Thirteenth(USACO)
- usaco--Friday the Thirteenth
- [USACO] Friday the Thirteenth
- usaco Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO:Friday the Thirteenth
- USACO -Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO--Friday the Thirteenth
- usaco Friday the Thirteenth
- usaco Friday the Thirteenth
- usaco Friday the Thirteenth
- USACO 1.1 Friday 日期问题
- ISO 9001: 2000 For Small Businesses
- org.apache.jasper.JasperException: Unable to compile class for JSP 解决方法
- Microsoft Visual Studio 2005 Unleashed
- 旋转卡壳——目录页
- Windows Server 2003 Security Infrastructures: Core Security Features
- 关于日期的处理 usaco Friday the Thirteeth
- Configuring ISA Server 2000
- Microsoft Money 2006 For Dummies
- Vision with Direction: A Systematic Introduction to Image Processing and Computer Vision
- Oracle Internals: Tips, Tricks, and Techniques for DBAs
- matlab FAQ
- Exploiting Software: How to Break Code
- 关闭当前页所打开的全部窗口!
- BEA WebLogic Platform 7