結果

問題 No.721 Die tertia (ディエ・テルツィア)
ユーザー miseboxmisebox
提出日時 2018-08-24 08:43:13
言語 Rust
(1.72.1)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,436 bytes
コンパイル時間 6,376 ms
コンパイル使用メモリ 132,684 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-01 03:58:48
合計ジャッジ時間 2,334 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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