結果

問題 No.227 簡単ポーカー
ユーザー yuto-ohtayuto-ohta
提出日時 2021-05-09 16:46:11
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,874 bytes
コンパイル時間 12,786 ms
コンパイル使用メモリ 222,760 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 02:25:58
合計ジャッジ時間 13,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	//五枚のカード(1~13の数が割り当てられる)
	var fiveCards []int

	// 標準入力から5つの数字を受け取る
	// ex) "1 2 3 4 5"
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	strFiveCards := strings.Fields(scanner.Text())
	if len(strFiveCards) != 5 {
		_, _ = fmt.Fprintln(os.Stderr, "error: 5つの数字を指定する")
	}
	for _, strNum := range strFiveCards {
		num, _ := strconv.Atoi(strNum)
		fiveCards = append(fiveCards, num)
	}
	sort.Ints(fiveCards)

	//1~13のそれぞれの数が
	//	カードの中にいくつ存在するかを数えて、配列に格納する
	var howManyEachNumber [13]int
	counter := 0
	for i := 1; i <= 13; i++ {
		for _, num := range fiveCards {
			if i == num {
				counter++
			}
		}
		howManyEachNumber[i-1] = counter
		counter = 0
	}

	//配列が
	//		3, 2を含んでいればFULL HOUSE
	if containSpecificNum(howManyEachNumber[:], 3) && containSpecificNum(howManyEachNumber[:], 2) {
		fmt.Println("FULL HOUSE")
		return
		//	3を含んでいれば
	} else if containSpecificNum(howManyEachNumber[:], 3) {
		fmt.Println("THREE CARD")
		return
	} else if containSpecificNum(howManyEachNumber[:], 2) {
		firstTwoIndex := getSpecificNumIndex(howManyEachNumber[:], 2)
		//	2, 2を含んでいれば
		if containSpecificNum(howManyEachNumber[firstTwoIndex+1:], 2) {
			fmt.Println("TWO PAIR")
			return
		}
		//	2を含んでいれば
		fmt.Println("ONE PAIR")
	} else {
		//	それ以外は NO HAND
		fmt.Println("NO HAND")
	}
}

func containSpecificNum(target []int, number int) bool {
	if getSpecificNumIndex(target, number) != -1 {
		return true
	}
	return false
}

func getSpecificNumIndex(target []int, number int) int {
	for i, el := range target {
		if el == number {
			return i
		}
	}
	return -1
}
0