結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー 特命ログイン特命ログイン
提出日時 2018-10-04 00:28:15
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,725 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 165,188 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 14:59:07
合計ジャッジ時間 1,368 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
        }
    }
}
0