結果

問題 No.227 簡単ポーカー
ユーザー eagleeagle
提出日時 2022-06-14 10:31:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,291 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 78,060 KB
実行使用メモリ 54,572 KB
最終ジャッジ日時 2024-04-10 02:17:01
合計ジャッジ時間 4,692 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
54,136 KB
testcase_01 AC 128 ms
54,108 KB
testcase_02 AC 125 ms
54,068 KB
testcase_03 AC 125 ms
53,888 KB
testcase_04 AC 127 ms
54,204 KB
testcase_05 AC 124 ms
54,096 KB
testcase_06 AC 114 ms
52,828 KB
testcase_07 AC 112 ms
52,944 KB
testcase_08 AC 114 ms
53,048 KB
testcase_09 AC 127 ms
53,940 KB
testcase_10 AC 115 ms
53,152 KB
testcase_11 AC 127 ms
54,176 KB
testcase_12 AC 127 ms
54,572 KB
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

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();
		}
		//カードを昇順に並び替える
		Arrays.sort(A);
		//フルハウス判定
		boolean three = false; //スリーカード判定
		boolean pair = false; //ペア判定
		boolean twoPair = false; //ツーペア判定
		String ans;
		//先頭から順に同じカードの数を数える
		for(int i = 0; i < A.length - 1; i++) {
			int cnt = 1;
			for(int j = i + 1; j < A.length; j++) {
				if(A[i] == A[j]) {
					cnt++;
				} else {
					i = j - 1;
					break;
				}
			}
			//スリーカード判定
			if(cnt >= 4) {
				break;
			} else if(cnt == 3) {
				three = true;
			//ペア判定
			} else if(cnt == 2 && !pair){
				pair = true;
			//ツーペア判定
			} else if(cnt == 2 && pair) {
				twoPair = true;
			}
		}
		//役判定
		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