結果

問題 No.227 簡単ポーカー
ユーザー eagleeagle
提出日時 2022-06-14 10:45:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 1,351 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 77,644 KB
実行使用メモリ 54,432 KB
最終ジャッジ日時 2024-04-10 02:40:42
合計ジャッジ時間 4,272 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
52,940 KB
testcase_01 AC 119 ms
54,156 KB
testcase_02 AC 119 ms
54,288 KB
testcase_03 AC 118 ms
53,960 KB
testcase_04 AC 119 ms
53,988 KB
testcase_05 AC 120 ms
54,304 KB
testcase_06 AC 116 ms
54,060 KB
testcase_07 AC 108 ms
52,964 KB
testcase_08 AC 107 ms
52,928 KB
testcase_09 AC 119 ms
54,432 KB
testcase_10 AC 115 ms
53,844 KB
testcase_11 AC 113 ms
53,248 KB
testcase_12 AC 127 ms
54,228 KB
testcase_13 AC 123 ms
54,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//与えられるカード
		int[] A = new int[5];
		for(int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}
		//確認した場所を記憶する配列
		int[] check = new int[A.length];
		//スリーカードか
		boolean three = false;
		//ペアか
		boolean pair = false;
		//ツーペアか
		boolean twoPair = false;
		//先頭から順に役を見つける
		for(int i = 0; i < A.length; i++) {
			//チェック済みカードは飛ばす
			if(check[i] == 1) {
				continue;
			}
			//同じカードの枚数を数える
			int cnt = 1;
			check[i] = 1;
			for(int j = i + 1; j < A.length; j++) {
				if(check[j] == 1) {
					continue;
				}
				if(A[i] == A[j]) {
					cnt++;
					check[j] = 1;
				}
			}
			if(cnt >= 4) {
				break;
			} else if(cnt == 3) {
				three = true;
			} else if(cnt == 2 && pair) {
				twoPair = true;
			} else if(cnt == 2) {
				pair = true;
			}
		}
		//役判定
		String ans;
		if(three && pair) {
			ans = "FULL HOUSE";
		}else if(three) {
			ans = "THREE CARD";
		} else if(twoPair) {
			ans = "TWO PAIR";
		} else if(pair) {
			ans = "ONE PAIR";
		} else {
			ans = "NO HAND";
		}
		System.out.println(ans);
	}
}
0