結果

問題 No.227 簡単ポーカー
ユーザー mochi8kmochi8k
提出日時 2016-08-10 09:00:08
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,124 bytes
コンパイル時間 16,680 ms
コンパイル使用メモリ 248,100 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:15:07
合計ジャッジ時間 14,470 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*
  5枚のカードが配られます。それぞれのカードには、1以上13以下のいずれかの整数が書かれています。カードに書かれている整数の組み合わせによって役が決まります。

  配られた5枚のカードが、以下のいずれの役に該当するかを調べてください。複数の役に該当する場合は、以下で先に記述した方の役に該当するものとします。

  FULL HOUSE
  ある数をちょうど3つと、別の数をちょうど2つ含む。
  THREE CARD
  ある数をちょうど3つ含む。
  TWO PAIR
  ある数をちょうど2つと、別の数をちょうど2つ含む。
  ONE PAIR
  ある数をちょうど2つ含む。
*/

package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()
	e := nextInt()

	cards := []int{a, b, c, d, e}
	cardMap := map[int]int{}

	for _, v := range cards {
		cardMap[v] = (cardMap[v] + 1)
	}

	allocationNumbers := make([]int, 0)
	for _, value := range cardMap {
		allocationNumbers = append(allocationNumbers, value)
	}

	sort.Ints(allocationNumbers)

	if isFullHouse(allocationNumbers) {
		fmt.Println("FULL HOUSE")
	} else if isThreeCard(allocationNumbers) {
		fmt.Println("THREE CARD")
	} else if isTwoPair(allocationNumbers) {
		fmt.Println("TWO PAIR")
	} else if isOnePair(allocationNumbers) {
		fmt.Println("ONE PAIR")
	} else {
		fmt.Println("NO HAND")
	}

}

func isFullHouse(allocationNumbers []int) bool {
	return reflect.DeepEqual(allocationNumbers, []int{2, 3})
}

func isThreeCard(allocationNumbers []int) bool {
	return reflect.DeepEqual(allocationNumbers, []int{1, 1, 3})
}

func isTwoPair(allocationNumbers []int) bool {
	return reflect.DeepEqual(allocationNumbers, []int{1, 2, 2})
}

func isOnePair(allocationNumbers []int) bool {
	return reflect.DeepEqual(allocationNumbers, []int{1, 1, 1, 2})
}
0