万年历

来源:互联网 发布:慧眼文字识别软件 编辑:程序博客网 时间:2024/04/29 07:42
#include<iostream>using namespace std;int isLeapYear(int year){if (year % 100 == 0 && year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)){return 1;}elsereturn 0;}int monthDays(int year,int month){int n[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };if (isLeapYear(year))n[1] = 29;return n[month - 1];}int dayNumber(int year,int month){int c,i,s = 0;int n[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };if (isLeapYear(year))n[1] = 29;for (i = 0; i<month - 1; i++){s = n[i] + s;}c = s + 1;return c;}int week(int year, int month, int c){int s;s = (year - 1 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + c) % 7;return s;}int main(){int year, month;int mon,d,k;while (cin >> year >> month){d=dayNumber(year,month);mon=monthDays(year,month);k=week(year, month, d);cout << "日" << '\t' << "一" << '\t' << "二" << '\t' << "三" << '\t' << "四" << '\t' << "五" << '\t' << "六" << endl;for (int i = 1; i <= mon; i++){if (i == 1){for (int j = 0; j<k; j++){cout << '\t';}}cout << i << '\t';if ((i + k) % 7 == 0){cout << endl;}}cout << endl << endl;}return 0;}

0 0
原创粉丝点击