-
Notifications
You must be signed in to change notification settings - Fork 0
/
19.1.go
56 lines (51 loc) · 1.15 KB
/
19.1.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
)
// 1900 1 1
var days = [...]int{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
func dayByYear(year int) int {
return (year-1900) * 365 +year/4-1900/4-(year/400-1900/400)
}
func dayInYear(year int, month int, day int) int {
isLeap := (year % 100 != 0 && year % 4 == 0) || (year % 100 == 0 && year % 400 == 0)
ret := 0
for i:= 1; i<month; i++ {
ret += days[i]
}
ret += day - 1
if isLeap && month > 2 {
ret ++
}
return ret
}
func calc(year int, month int, day int, v bool) int {
ret := dayByYear(year) + dayInYear(year, month, day)
if v {
fmt.Printf("%04d-%02d-%02d %d\n", year,month, day, ret)
}
return ret
}
func main() {
calc(1900, 1, 1, true)
calc(1900, 2, 28, true)
calc(1900, 3, 1, true)
calc(1901, 1, 1, true)
calc(1904, 2, 28, true)
calc(1904, 3, 1, true)
calc(2000, 1, 1, true)
calc(2000, 2, 1, true)
calc(2000, 2, 29, true)
calc(2000, 3, 1, true)
cnt := 0
for i:=1901;i<=2000;i++ {
for j:=1;j<=12;j++ {
d := calc(i, j, 1, false)
if d % 7 == 6 {
//fmt.Println("got ", i, j, 1)
cnt ++
}
}
}
fmt.Println("result ", cnt)
}