You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
4.7 KiB

#include<bits/stdc++.h>
using namespace std;
int Week(int day) {
//这一年 1 月 1 日是星期几
int week = (day % 7) +1;
cout << "星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日" << endl;
for(int i = 0; i < week -1; i++) {
cout << "\t";
}//打印第一天前面的空格
}
int main() {
cout << "本程序为实现万年历的功能,请输入要查找的年份:" << endl;
int ye;
cin >> ye; //要查看的年份
int year = ye - 1;
//从公元元年 1 月 1 日到这一年 1 月 1 日一共的天数
int day = ((year / 4) - (year / 100) + (year / 400)) * 366 + (year - ((year / 4) - (year / 100) + (year / 400))) * 365;
int month1[31] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
int month2b[28] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28};
int month2a[29] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29};
int month4[30] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
int Jan = sizeof(month1) / sizeof(0);
int Feb;
int Apr = sizeof(month4) / sizeof(0);
//一月
cout << "一月" << endl;
Week(day);
for(int i = 0; i < sizeof(month1) / sizeof(0); i++) {
cout << month1[i];
if(((day + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//二月
int day1 = day + Jan; //二月之前的天数
if((day1 % 7) != 0)
cout << "\n";
cout << "二月" << endl;
Week(day1);
if((ye % 4 == 0 && ye % 100 != 0) || ye % 400 == 0) {
for(int i = 0; i < sizeof(month2a) / sizeof(0); i++) {
cout << month2a[i];
if(((day1 + month2a[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
Feb = sizeof(month2a) / sizeof(0);
} else {
for(int i = 0; i < sizeof(month2b) / sizeof(0); i++) {
cout << month2b[i];
if(((day + Jan + month2b[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
Feb = sizeof(month2b) / sizeof(0);
}
//三月
int day2 = day + Jan + Feb;
if((day2 % 7) != 0)
cout << "\n";
cout << "三月" << endl;
Week(day2);
for(int i = 0; i < sizeof(month1) / sizeof(0); i++) {
cout << month1[i];
if(((day2 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//四月
int day3 = day + Jan * 2 + Feb;
if((day3 % 7) != 0)
cout << "\n";
cout << "四月" << endl;
Week(day3);
for(int i = 0; i < sizeof(month4) / sizeof(0); i++) {
cout << month1[i];
if(((day3 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//五月
int day4 = day + Jan * 2 + Feb + Apr;
if((day4 % 7) != 0)
cout << "\n";
cout << "五月" << endl;
Week(day4);
for(int i = 0; i < sizeof(month1) / sizeof(0); i++) {
cout << month1[i];
if(((day4 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//六月
int day5 = day + Jan * 3 + Feb + Apr;
if((day5 % 7) != 0)
cout << "\n";
cout << "六月" << endl;
Week(day5);
for(int i = 0; i < sizeof(month4) / sizeof(0); i++) {
cout << month1[i];
if(((day5 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//七月
int day6 = day + Jan * 3 + Feb + Apr * 2;
if((day6 % 7) != 0)
cout << "\n";
cout << "七月" << endl;
Week(day6);
for(int i = 0; i < sizeof(month1) / sizeof(0); i++) {
cout << month1[i];
if(((day6 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//八月
int day7 = day + Jan * 4 + Feb + Apr * 2;
if((day7 % 7) != 0)
cout << "\n";
cout << "八月" << endl;
Week(day7);
for(int i = 0; i < sizeof(month1) / sizeof(0); i++) {
cout << month1[i];
if(((day7 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//九月
int day8 = day + Jan * 5 + Feb + Apr * 2;
if((day8 % 7) != 0)
cout << "\n";
cout << "九月" << endl;
Week(day8);
for(int i = 0; i < sizeof(month4) / sizeof(0); i++) {
cout << month1[i];
if(((day8 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//十月
int day9 = day + Jan * 5 + Feb + Apr * 3;
if((day9 % 7) != 0)
cout << "\n";
cout << "十月" << endl;
Week(day9);
for(int i = 0; i < sizeof(month1) / sizeof(0); i++) {
cout << month1[i];
if(((day9 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//十一月
int day10 = day + Jan * 6 + Feb + Apr * 3;
if((day10 % 7) != 0)
cout << "\n";
cout << "十一月" << endl;
Week(day10);
for(int i = 0; i < sizeof(month4) / sizeof(0); i++) {
cout << month1[i];
if(((day10 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
//十二月
int day11 = day + Jan * 6 + Feb + Apr * 4;
if((day11 % 7) != 0)
cout << "\n";
cout << "十二月" << endl;
Week(day11);
for(int i = 0; i < sizeof(month1) / sizeof(0); i++) {
cout << month1[i];
if(((day11 + month1[i]) % 7) == 0)
cout << "\n";
else
cout << "\t";
}
}