結果
| 問題 |
No.721 Die tertia (ディエ・テルツィア)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-24 08:43:13 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,436 bytes |
| コンパイル時間 | 14,231 ms |
| コンパイル使用メモリ | 385,720 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-03 06:14:50 |
| 合計ジャッジ時間 | 14,617 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
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();
}