結果

問題 No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
ユーザー Masaki KitaguchiMasaki Kitaguchi
提出日時 2022-01-07 23:59:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,986 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 170,232 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 19:07:06
合計ジャッジ時間 2,526 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut buf = String::new();
    let mut input = {
        use std::io::Read;
        std::io::stdin().read_to_string(&mut buf).unwrap();
        buf.split_whitespace()
    };

    let n: String = input.next().unwrap().parse().unwrap();

    let n_2: String = n
        .chars()
        .map(|c| match c {
            'A' => String::from("1010"),
            'B' => String::from("1011"),
            'C' => String::from("1100"),
            'D' => String::from("1101"),
            'E' => String::from("1110"),
            'F' => String::from("1111"),
            _ => unreachable!(),
        })
        .collect();

    let n_8: String = n_2
        .chars()
        .rev()
        .enumerate()
        .fold(String::new(), |acc, (i, c)| {
            if i % 3 == 0 && i != 0 {
                String::from(c) + "," + acc.as_str()
            } else {
                String::from(c) + acc.as_str()
            }
        })
        .split(",")
        .map(String::from)
        .map(|s| match s.len() {
            1 => String::from("00") + s.as_str(),
            2 => String::from("0") + s.as_str(),
            _ => s,
        })
        .map(|s| match s.as_str() {
            "000" => String::from("0"),
            "001" => String::from("1"),
            "010" => String::from("2"),
            "011" => String::from("3"),
            "100" => String::from("4"),
            "101" => String::from("5"),
            "110" => String::from("6"),
            "111" => String::from("7"),
            _ => unreachable!(),
        })
        .collect();

    let mut count = vec![0; 8];
    for c in n_8.chars() {
        let i = c.to_digit(8).unwrap() as usize;
        count[i] += 1;
    }

    let max = count.iter().fold(0, |acc, &k| acc.max(k));

    let output = count
        .iter()
        .enumerate()
        .filter(|(_, k)| **k == max)
        .map(|(i, _)| format!("{}", i))
        .collect::<Vec<_>>()
        .join(" ");

    println!("{}", output);
}
0