結果
| 問題 | No.431 死亡フラグ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-02 19:43:06 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,076 bytes |
| 記録 | |
| コンパイル時間 | 11,978 ms |
| コンパイル使用メモリ | 391,196 KB |
| 最終ジャッジ日時 | 2024-11-15 01:25:18 |
| 合計ジャッジ時間 | 12,732 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error[E0782]: trait objects must include the `dyn` keyword --> src/main.rs:5:45 | 5 | type Result<T> = std::result::Result<T, Box<Error>>; | ^^^^^ | help: add `dyn` keyword before this trait | 5 | type Result<T> = std::result::Result<T, Box<dyn Error>>; | +++ For more information about this error, try `rustc --explain E0782`. error: could not compile `main` (bin "main") due to 1 previous error
ソースコード
use std::io;
use std::error::Error;
use std::fmt;
type Result<T> = std::result::Result<T, Box<Error>>;
enum State {
Dead,
Survived,
}
impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
State::Dead => write!(f, "DEAD"),
State::Survived => write!(f, "SURVIVED"),
}
}
}
fn get_line() -> Result<String> {
let mut input = String::new();
io::stdin().read_line(&mut input)?;
Ok(input)
}
fn read_flags(input: String) -> Result<(u8, u8, u8, u8)> {
let flags: Vec<&str> = input.trim().split(' ').collect();
Ok((flags[0].parse()?,
flags[1].parse()?,
flags[2].parse()?,
flags[3].parse()?))
}
fn check_dead_or_live(d1: u8, d2: u8, d3: u8, s: u8) -> State {
if s == 1 {
return State::Survived;
}
if (d1 + d2 + d3) < 2 {
return State::Survived;
}
State::Dead
}
fn main() {
let (d1, d2, d3, s) = get_line().and_then(read_flags).unwrap();
println!("{}", check_dead_or_live(d1, d2, d3, s));
}