結果
| 問題 | No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-01-07 23:59:45 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,986 bytes | 
| コンパイル時間 | 13,933 ms | 
| コンパイル使用メモリ | 401,792 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-14 09:18:21 | 
| 合計ジャッジ時間 | 15,157 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 | 
ソースコード
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);
}
            
            
            
        