万年历
来源:互联网 发布:arta软件中文版 编辑:程序博客网 时间:2024/05/07 20:36
#include <iostream>#include <cstdio>using namespace std;int year,month;int m=1;int isleapyear(int year){ int isok=0; return isok=year%4==0 || year%400==0 ? 1 : 0;}int yeardays(int year){ int days=0; return days=isleapyear(year)?366:365;}int yearmonthdays(int year,int month){ int days=0; switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days=31; break; case 4: case 6: case 9: case 11: days=30; break; case 2: days=(isleapyear(year)==1?29:28); break; } return days;}int firstmonthweekday(int year,int month){ int days=0; if(year>=2000) { for(int i=2000; i<year; i++) days+=yeardays(i); for(int i=1; i<month; i++) days+=yearmonthdays(year,i); } if(year<2000) { for(int i=year+1; i<2000; i++) days+=yeardays(i); for(int i=month; i<=12; i++) days+=yearmonthdays(year,i); } return days;}int yearmonthweekday(int year,int month){ int weekday=0; if(year>=2000) { int n; n=firstmonthweekday(year,month); weekday=(n+6)%7; } else { int n; n=firstmonthweekday(year,month); weekday=6-n%7; } return weekday;};void displayyearmonth(int year,int month){ cout << "--------------" << year << "年" << month << "月" << "-----------------" << endl; cout <<"日\t"<<"一\t"<<"二\t"<<"三\t"<<"四\t"<<"五\t"<<"六\t"<<"周\n"; int count=0; for(int i=0; i<yearmonthweekday(year,month); i++) { cout << "\t"; count++; } for(int j=1; j<=yearmonthdays(year,month); j++) { cout << j << "\t"; count++; if(count%7==0) { cout << m++ << "\t" << endl; } } if(count%7!=0) { for(int i=0; i<7-count%7; i++) cout << "\t"; cout << m++ << endl; }}void displayyear(int year){ for(int i=1; i<=12; i++) { if(yearmonthweekday(year,i)!=0&&i!=1) { m--; } displayyearmonth(year,i); }}int main(){ cin >> year; displayyear(year); return 0;}
0 0
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- 万年历
- IOS 扫二维码
- cv::Mat 的子矩阵赋值
- 【BZOJ1061】【NOI2008】志愿者招募 费用流神题、单纯形裸题(代码费用流)
- java 线程和线程池对比
- LESS CSS 框架简介
- 万年历
- 抽屉-YRSideViewController的使用
- spring quartz:Instantiation of bean failed; nested exception is java.lang.IncompatibleClassChangeErr
- cocos2dx事件监听器
- 上早景中天早帮中睥想打景虽临蝇
- NYOJ 972 核桃的数量 (最小公倍数)
- 腺体早盘廖晓乔是末年刘采看我柞
- jni开发之配置ndk、Javap、javah命令工具
- python学习笔记——多线程编程