Fengyi Chen 4b8c0c58eb d
2024-05-14 22:28:09 +08:00

68 lines
1.3 KiB
C++
Raw Blame History

#include <iostream>
using namespace std;
bool isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0 && year % 3200 != 0)){
return true;
}
else{
return false;
}
}
int getDaysOfMonth(int year, int month) {
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
return 31;
}
if(month == 4 || month == 6 || month == 9 || month == 11){
return 30;
}
if(month == 2){
if(isLeapYear(year)==1){
return 29;
}else{
return 28;
}
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD>Ԫ2021<32><31>1<EFBFBD><31>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
int calcDays(int year, int month, int day) {
int days = 0;
for (int i = 2021; i < year; i++) {
if(isLeapYear(i)==1){
days +=366;
}else{
days +=365;
}
}
for (int i = 1; i < month; i++) {
days += getDaysOfMonth(year, i);
}
days += day-1;
return days;
}
int calcWeekday(int days) {
days+=5;
days%=7;
if(days==0){
return 7;
}
return days;
}
int main() {
int year, month, day;
cin >> year >> month >> day;
int days = calcDays(year, month, day);
int weekday = calcWeekday(days);
cout << days << endl;
cout << '*' << weekday << endl;
return 0;
}