結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー miseboxmisebox
提出日時 2018-08-24 08:35:10
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 140,360 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-01 03:00:40
合計ジャッジ時間 2,171 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

struct Date {
    year: u16,
    month: u8,
    day: u8,
}


impl Date {

  #[allow(dead_code)]
  fn is_leap_year(&self) -> bool {
    let y = self.year;
    y % 4 == 0 && (y % 100 > 0 || y % 400 == 0)
  }

  #[allow(dead_code)]
  fn get_month_lastday(&self) -> u8 {
    match self.month {
      4|6|9|11 => 30,
      2 =>  match self.is_leap_year() {
              true => 29,
              _ => 28,
            },
      _ => 31,
    }
  }

  #[allow(dead_code)]
  fn increase_year(&mut self) {
    self.year = self.year + 1;
  }

  #[allow(dead_code)]
  fn increase_month(&mut self) {
    self.month = match self.month {
      12 => {
        self.increase_year();
        1
      },
      _ => self.month + 1,
    };
  }

  #[allow(dead_code)]
  fn increase_day(&mut self) {
    if self.day == self.get_month_lastday() {
      self.increase_month();
      self.day = 1;
    } else {
      self.day += 1;
    }
  }

  #[allow(dead_code)]
  fn show(&self) {
    println!("{0:>04}-{1:>02}-{2:>02}", self.year, self.month, self.day);
  }
}

use std::io;

fn main(){
  let mut input = String::new();
  io::stdin().read_line(&mut input).ok();
  let mut v = input.trim().split("/");
  let y: u16 = v.next().unwrap().parse().unwrap();
  let m: u8 = v.next().unwrap().parse().unwrap();
  let d: u8 = v.next().unwrap().parse().unwrap();

  let mut d = Date {year:y, month:m, day:d};
  d.increase_day();
  d.increase_day();
  d.show();
}
0