結果
| 問題 |
No.227 簡単ポーカー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-12 21:50:01 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,465 bytes |
| コンパイル時間 | 12,395 ms |
| コンパイル使用メモリ | 387,200 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-14 12:56:33 |
| 合計ジャッジ時間 | 13,394 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
コンパイルメッセージ
warning: fields `n2` and `n3` are never read
--> src/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
--> src/main.rs:7:13
|
7 | TwoPair{a: u32, b: u32},
| ------- ^ ^
| |
| fields in this variant
ソースコード
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);
}