Skip to content

Commit 67ddee2

Browse files
committed
Solve B in arc002
1 parent ec121bc commit 67ddee2

File tree

1 file changed

+29
-1
lines changed
  • atcoder/rust/arc002/src/bin

1 file changed

+29
-1
lines changed

atcoder/rust/arc002/src/bin/b.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,36 @@ use proconio::*;
1212
use proconio::marker::*;
1313
use superslice::*;
1414

15-
fn main() {
15+
fn main() {
1616
input! {
1717
ymd: String,
1818
}
19+
20+
let nums = ymd.split("/").
21+
collect::<Vec<&str>>().
22+
iter().
23+
map(|i| i.to_string().parse::<usize>().unwrap()).
24+
collect::<Vec<usize>>();
25+
26+
let mut year = nums[0];
27+
let mut month = nums[1];
28+
let mut day = nums[2];
29+
30+
loop {
31+
if year % month == 0 && year / month % day == 0 {
32+
return println!("{}/{:02}/{:02}", year, month, day);
33+
}
34+
let is_leap_year = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
35+
if day == 31 || (month == 2 && (day == if is_leap_year { 29 } else { 28 })) || (vec![4, 6, 9, 11].contains(&month) && day == 30) {
36+
day = 1;
37+
if month == 12 {
38+
month = 1;
39+
year += 1;
40+
} else {
41+
month += 1;
42+
}
43+
} else {
44+
day += 1;
45+
};
46+
}
1947
}

0 commit comments

Comments
 (0)