結果

問題 No.333 門松列を数え上げ
ユーザー tubo28tubo28
提出日時 2016-04-04 02:56:44
言語 Rust
(1.77.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,668 bytes
コンパイル時間 12,306 ms
コンパイル使用メモリ 401,960 KB
最終ジャッジ日時 2024-04-27 02:18:48
合計ジャッジ時間 12,980 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
error: use of deprecated `try` macro
  --> src/main.rs:33:17
   |
33 |         let s = try!(self.fetch_token());
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
33 -         let s = try!(self.fetch_token());
33 +         let s = self.fetch_token()?;
   |
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
   |
33 |         let s = r#try!(self.fetch_token());
   |                 ++

error: use of deprecated `try` macro
  --> src/main.rs:34:17
   |
34 |         let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
34 -         let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
34 +         let t = s.parse::<T>().map_err(|_| "Parse error")?;
   |
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
   |
34 |         let t = r#try!(s.parse::<T>().map_err(|_| "Parse error"));
   |                 ++

warning: unused import: `std::cmp::*`
 --> src/main.rs:1:5
  |
1 | use std::cmp::*;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: could not compile `main` (bin "main") due to 2 previous errors; 1 warning emitted

ソースコード

diff #

use std::cmp::*;

fn main(){
    let mut sc = Scanner::new();
    while let Ok(a) = sc.wrapped::<i64>() {
        let b: i64 = sc.next();
        println!("{}", if a < b {
            if a == 1 && b == 2 { 0 }
            else if a+1 == b { a-1 }
            else { (b-a-1) + (a-1) }
        } else {
            if a == 2000000000 { a-b-1 }
            else if a-1==b { 2000000000-a }
            else { (2000000000-a) + (a-b-1) }
        }
        );
    }
}

#[allow(dead_code)]
struct Scanner {
    token_buffer : Vec<String>,
    index : usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner { token_buffer: vec![], index: 0 }
    }

    fn wrapped<T>(&mut self) -> Result<T,&str> where T: std::str::FromStr {
        let s = try!(self.fetch_token());
        let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
        Ok(t)
    }
    fn next<T>(&mut self) -> T where T: std::str::FromStr {
        self.wrapped::<T>().unwrap()
    }

    fn fetch_token(&mut self) -> Result<&String,&str> {
        while self.index >= self.token_buffer.len() {
            let mut st = String::new();
            while st.trim() == "" {
                match std::io::stdin().read_line(&mut st) {
                    Ok(l) if l > 0 => continue,
                    Ok(_)  => return Err("End of file"),
                    Err(_) => return Err("Failed to read line"),
                }
            }
            self.token_buffer = st.split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.index = 0;
        }

        self.index += 1;
        Ok(&self.token_buffer[self.index - 1])
    }
}
0