結果

問題 No.227 簡単ポーカー
ユーザー Tadatoshi TokutakeTadatoshi Tokutake
提出日時 2018-05-25 14:36:59
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,046 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 154,460 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 03:26:08
合計ジャッジ時間 2,479 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 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,376 KB
testcase_13 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;
use std::io::stdin;

fn readln() -> String {
  let mut s = String::new();
  stdin().read_line(&mut s).unwrap();
  s
}

fn main() {
  let hand = readln()
    .trim()
    .split_whitespace()
    .map(|card| card.parse::<i32>().unwrap())
    .collect::<Vec<i32>>();
  let count_map = hand
    .into_iter()
    .fold(HashMap::new(), |mut hm: HashMap<i32, i32>, card| {
      {
        let entry = hm.entry(card).or_insert(0);
        *entry += 1;
      }
      hm
    });
  let count_of_count_map = count_map
    .values()
    .fold(HashMap::new(), |mut hm: HashMap<i32, i32>, count| {
      {
        let entry = hm.entry(*count).or_insert(0);
        *entry += 1;
      }
      hm
    });

  match (count_of_count_map.get(&3), count_of_count_map.get(&2)) {
    (Some(&1), Some(&1)) => println!("FULL HOUSE"),
    (Some(&1), None    ) => println!("THREE CARD"),
    (None    , Some(&2)) => println!("TWO PAIR"),
    (None    , Some(&1)) => println!("ONE PAIR"),
    _                    => println!("NO HAND"),
  };
}
0