結果

問題 No.227 簡単ポーカー
ユーザー eagleeagle
提出日時 2022-06-14 10:34:32
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,326 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 78,184 KB
実行使用メモリ 55,476 KB
最終ジャッジ日時 2024-04-10 02:20:33
合計ジャッジ時間 4,569 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
54,044 KB
testcase_01 WA -
testcase_02 AC 124 ms
54,076 KB
testcase_03 AC 122 ms
53,996 KB
testcase_04 AC 109 ms
52,856 KB
testcase_05 AC 114 ms
53,012 KB
testcase_06 AC 122 ms
54,232 KB
testcase_07 AC 129 ms
54,428 KB
testcase_08 AC 124 ms
54,044 KB
testcase_09 AC 125 ms
54,136 KB
testcase_10 AC 114 ms
52,996 KB
testcase_11 AC 118 ms
55,476 KB
testcase_12 AC 117 ms
53,380 KB
testcase_13 AC 124 ms
53,972 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();
		}
		//カードを昇順に並び替える
		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;
				if(i == 2) {
					break;
				}
			//ペア判定
			} 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