use std::io::{stdin,Read}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); macro_rules! get { ($t:ty) => (get().parse::<$t>().unwrap()); () => (get!(i64)); } let mut d = get!(Date); d.add_days(2); println!("{}", d); // println!("{:?}", d); } #[derive(Debug)] struct Date { year: i32, month: i32, day: i32 } impl std::str::FromStr for Date { type Err = std::string::ParseError; fn from_str(s: &str) -> Result { let tok: Vec = s.split('/').filter_map(|s|s.parse().ok()).collect(); Ok(Date{year: tok[0], month: tok[1], day: tok[2]}) } } impl std::fmt::Display for Date { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(),std::fmt::Error> { write!(f, "{:04}/{:02}/{:02}", self.year, self.month, self.day) } } impl Date { fn add_days(&mut self, d: i32) -> &Self { self.day += d; let md = match self.month { 4|6|9|11 => 30, 2 if self.year % 400 == 0 => 29, 2 if self.year % 100 == 0 => 28, 2 if self.year % 4 == 0 => 29, 2 => 28, _ => 31, }; if self.day > md { self.day -= md; if self.month < 12 { self.month += 1; } else { self.month = 1; self.year += 1; } } self } }