結果
| 問題 |
No.2385 Parse Integer with Radix
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 21:26:29 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,058 bytes |
| コンパイル時間 | 17,897 ms |
| コンパイル使用メモリ | 377,772 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 22:41:14 |
| 合計ジャッジ時間 | 15,104 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 |
ソースコード
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
}