結果

問題 No.2087 基数の変換
ユーザー phsplsphspls
提出日時 2022-10-01 10:56:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 153,016 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 03:24:18
合計ジャッジ時間 2,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `BASE` should have a snake case name
 --> Main.rs:3:9
  |
3 |     let BASE: Vec<char> = "0123456789abcdefghijklmnopqrstuvwxyz".chars().collect();
  |         ^^^^ help: convert the identifier to snake case: `base`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn basefrom10(n: usize, base: usize) -> String {
    let BASE: Vec<char> = "0123456789abcdefghijklmnopqrstuvwxyz".chars().collect();
    let mut ex = 1u32;
    while n > base.pow(ex) - 1 {
        ex+=1;
    }
    let mut rest = n;
    (0..ex).rev().map(|i| {
        let temp = base.pow(i);
        let ret = rest / temp;
        rest -= ret * temp;
        BASE[ret].to_string()
    })
    .collect::<Vec<_>>()
    .join("")
}

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut m = String::new();
    std::io::stdin().read_line(&mut m).ok();
    let m: usize = m.trim().parse().unwrap();

    println!("{}", basefrom10(m, n));
}
0