結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー 特命ログイン特命ログイン
提出日時 2018-10-04 00:07:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,545 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 156,800 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 14:57:35
合計ジャッジ時間 1,199 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 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);
    
    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<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 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
    }
}
0