50048. Count the days
難度:2/51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include "count_day.h"
int is_leap(int year){
return (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
}
void count_day(int year, int day, int month, int results[7]){
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(is_leap(year)) days[2] = 29;
for(int i = 1; i < month; i++){
day += days[i];
}
day %= 7;
for(int i = 0; i < days[month]; i++){
results[(day + i) % 7]++;
}
}
50048. Count the days
https://aaronlin1229.github.io/judgegirl_50048/