init
This commit is contained in:
7
problems/p19/Cargo.toml
Normal file
7
problems/p19/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "p19"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.41"
|
||||
19
problems/p19/src/main.rs
Normal file
19
problems/p19/src/main.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use chrono::{Datelike, NaiveDate, Weekday};
|
||||
|
||||
fn main() {
|
||||
let mut sum = 0;
|
||||
for year in 1901..=2000 {
|
||||
for month in 1..=12 {
|
||||
let date = NaiveDate::from_ymd_opt(year, month, 1).unwrap();
|
||||
|
||||
// 获取星期几
|
||||
let weekday = date.weekday();
|
||||
|
||||
// 判断是否为特定星期
|
||||
if weekday == Weekday::Sun {
|
||||
sum += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("{sum}")
|
||||
}
|
||||
Reference in New Issue
Block a user