結果
| 問題 | 
                            No.721 Die tertia (ディエ・テルツィア)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             特命ログイン
                         | 
                    
| 提出日時 | 2018-10-04 00:28:15 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,725 bytes | 
| コンパイル時間 | 12,242 ms | 
| コンパイル使用メモリ | 401,468 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-12 10:38:52 | 
| 合計ジャッジ時間 | 13,315 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 18 | 
ソースコード
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::Date);
    
    d.add_days(2);
    
    println!("{}", d);
    // println!("{:?}", d);
}
pub mod date {
    use std::{str,fmt,string};
    #[derive(Debug)]
    pub struct Date { year: i32, month: i32, day: i32 }
    impl str::FromStr for Date {
        type Err = string::ParseError;
        fn from_str(s: &str) -> Result<Self,Self::Err> {
            let tok: Vec<i32> = s.split('/').filter_map(|s|s.parse().ok()).collect();
            Ok(Date{year: tok[0], month: tok[1], day: tok[2]})
        }
    }
    impl fmt::Display for Date {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            write!(f, "{:04}/{:02}/{:02}", self.year, self.month, self.day)
        }
    }
    impl Date {
        pub 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
        }
    }
}
            
            
            
        
            
特命ログイン