文章
27
粉丝
86
获赞
10
访问
30.4k
C++
终于AC了!提交了5遍。分数20->0->0->40->80->100
暴力求解。(公元1年1月1日Monday)
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
map<string, int> monthMap;
int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string dayInWeek[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
bool isLeapYear(int year){
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
int cntDays(int year, int month, int day){
int sum = 0;
for(int i = 1; i < year; i++){
if(isLeapYear(i)){
sum += 366;
}
else{
sum += 365;
}
}
for(int i = 1; i < month; i++){
if(isLeapYear(year)){
daysInMonth[1] = 29;
}
else{
daysInMonth[1] = 28;
}
sum += daysInMonth[i - 1];
}
for(int i = 1; i < day; i++){
sum++;
}
return sum;
}
int main(){
monthMap["January"] = 1; monthMap["February"] = 2; monthMa...
登录后发布评论
暂无评论,来抢沙发