結果

問題 No.1468 Colourful Pastel
ユーザー mtwtkman
提出日時 2021-04-06 19:59:31
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 32 ms / 1,000 ms
コード長 1,573 bytes
コンパイル時間 11,232 ms
コンパイル使用メモリ 401,676 KB
実行使用メモリ 14,124 KB
最終ジャッジ日時 2024-06-11 17:35:35
合計ジャッジ時間 12,846 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: field `num` is never read
  --> src/main.rs:30:5
   |
29 | struct Input {
   |        ----- field in this struct
30 |     num: usize,
   |     ^^^
   |
   = note: `#[warn(dead_code)]` on by default

ソースコード

diff #

mod p1468 {
    use std::collections::BTreeMap;

    fn gather(v: Vec<String>) -> BTreeMap<String, usize> {
        v.into_iter().fold(BTreeMap::new(), |mut acc, s| {
            let count = acc.get(&s).unwrap_or(&0);
            acc.insert(s, count + 1);
            acc
        })
    }

    pub fn solve(begin: Vec<String>, after: Vec<String>) -> String {
        let begin_map = gather(begin);
        let after_map = gather(after);

        for (k, v) in begin_map.into_iter() {
            if let Some(taken) = after_map.get(&k) {
                if taken != &v {
                    return k
                }
            } else {
                return k
            }
        }
        return "--".to_string()
    }
}

struct Input {
    num: usize,
    begin: Vec<String>,
    after: Vec<String>,
}

impl Input {
    fn readline(len: usize) ->  Vec<String> {
        use std::io::{self, BufRead};

        let stdin = io::stdin();
        let lines = stdin.lock().lines().map(|l| l.unwrap().to_string());
        lines.take(len).collect()
    }

    fn accept(len: usize) -> Self {
        let lines = Self::readline(len);
        let num = lines[0].parse::<usize>().unwrap();
        let begin = lines[1].split(" ").map(|s| s.to_string()).collect::<Vec<_>>();
        let after = lines[2].split(" ").map(|s| s.to_string()).collect::<Vec<_>>();
        Self {
            num,
            begin,
            after,
        }
    }
}

fn main() {
    let args = Input::accept(3);
    let result = p1468::solve(args.begin, args.after);
    println!("{}", result);
}
0