結果
| 問題 |
No.721 Die tertia (ディエ・テルツィア)
|
| コンテスト | |
| ユーザー |
特命ログイン
|
| 提出日時 | 2018-10-04 00:10:54 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,532 bytes |
| コンパイル時間 | 11,996 ms |
| コンパイル使用メモリ | 391,036 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-12 10:37:06 |
| 合計ジャッジ時間 | 12,959 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 18 |
ソースコード
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) -> std::fmt::Result {
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
}
}
特命ログイン