結果

問題 No.2385 Parse Integer with Radix
ユーザー あさくちあさくち
提出日時 2023-07-21 21:26:29
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,058 bytes
コンパイル時間 2,537 ms
コンパイル使用メモリ 161,700 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 21:14:16
合計ジャッジ時間 3,231 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let q = input_value();

    for _ in 0..q {
        let s = input_string();

        if s.starts_with("0b") {
            let num = usize::from_str_radix(&s[2..], 2);
            println!("{}", num.unwrap());
        } else if s.starts_with("0o") {
            let num = usize::from_str_radix(&s[2..], 8);
            println!("{}", num.unwrap());
        } else if s.starts_with("0x") {
            let num = usize::from_str_radix(&s[2..], 16);
            println!("{}", num.unwrap());
        } else {
            println!("{}", s);
        }
    }
}

fn input_value<T>() -> T
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    let n = buf.parse().unwrap();

    n
}

fn input_string() -> String {
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    buf
}
0