結果

問題 No.227 簡単ポーカー
ユーザー wraiknywraikny
提出日時 2018-03-12 21:50:01
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,465 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 162,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 21:32:11
合計ジャッジ時間 1,410 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 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 0 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: fields `n2` and `n3` are never read
 --> main.rs:5:15
  |
5 |     FullHouse{n2: u32, n3: u32},
  |     --------- ^^       ^^
  |     |
  |     fields in this variant
  |
  = note: `#[warn(dead_code)]` on by default

warning: fields `a` and `b` are never read
 --> main.rs:7:13
  |
7 |     TwoPair{a: u32, b: u32},
  |     ------- ^       ^
  |     |
  |     fields in this variant

warning: 2 warnings emitted

ソースコード

diff #

use std::io;

#[derive(Clone)]
enum Hand {
    FullHouse{n2: u32, n3: u32},
    ThreeCard{n: u32},
    TwoPair{a: u32, b: u32},
    OnePair{n: u32},
    NoHand,
}

fn main() {
    let mut input = String::new();

    io::stdin().read_line(&mut input).unwrap();

    let nums = input.split_whitespace()
                    .map(|x| x.trim().parse::<u32>().unwrap())
                    .collect::<Vec<u32>>();

    use Hand::{NoHand, OnePair, TwoPair, ThreeCard, FullHouse};

    let mut hand = NoHand;

    for &i in nums.iter() {
        let h = &mut hand;
        match *h {
            FullHouse{n2: _, n3: _} => (),
            _ => {
                let s = nums.iter().fold(0, |sum, x| sum + ((*x==i) as u32));
                *h = match *h {
                        NoHand if s == 2 => OnePair{n : i},
                        NoHand if s == 3 => ThreeCard{n: i},
                        OnePair{n: x} if s == 2 && x != i => TwoPair{a: x, b: i},
                        OnePair{n: x} if s == 3 => FullHouse{n2: x, n3: i},
                        ThreeCard{n: x} if s == 2 => FullHouse{n3: x, n2: i},
                        _ => (*h).clone(),
                }
            }
        }
    };

    let output = match hand {
        NoHand => "NO HAND",
        OnePair{n: _} => "ONE PAIR",
        TwoPair{a: _, b: _} => "TWO PAIR",
        ThreeCard{n: _} => "THREE CARD",
        FullHouse{n2: _, n3: _} => "FULL HOUSE",
    };

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