結果

問題 No.431 死亡フラグ
ユーザー halshiphalship
提出日時 2016-10-23 15:16:37
言語 Rust
(1.77.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,101 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 76,908 KB
最終ジャッジ日時 2023-08-15 17:57:21
合計ジャッジ時間 2,025 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
error: use of deprecated `try` macro
  --> Main.rs:23:5
   |
23 |     try!(io::stdin().read_line(&mut input));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
23 -     try!(io::stdin().read_line(&mut input));
23 +     io::stdin().read_line(&mut input)?;
   |
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
   |
23 |     r#try!(io::stdin().read_line(&mut input));
   |     ++

error: use of deprecated `try` macro
  --> Main.rs:29:9
   |
29 |     Ok((try!(flags[0].parse()),
   |         ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
29 -     Ok((try!(flags[0].parse()),
29 +     Ok((flags[0].parse()?,
   |
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
   |
29 |     Ok((r#try!(flags[0].parse()),
   |         ++

error: use of deprecated `try` macro
  --> Main.rs:30:9
   |
30 |         try!(flags[1].parse()),
   |         ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
30 -         try!(flags[1].parse()),
30 +         flags[1].parse()?,
   |
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
   |
30 |         r#try!(flags[1].parse()),
   |         ++

error: use of deprecated `try` macro
  --> Main.rs:31:9
   |
31 |         try!(flags[2].parse()),
   |         ^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
31 -         try!(flags[2].parse()),
31 +         flags[2].parse()?,
   |
help: 

ソースコード

diff #

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();
    try!(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((try!(flags[0].parse()),
        try!(flags[1].parse()),
        try!(flags[2].parse()),
        try!(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));
}
0