SHOW:
|
|
- or go back to the newest paste.
1 | public class FullHouseJokers { | |
2 | ||
3 | public static boolean isFullHouse(Card[] hand){ | |
4 | String firstFace = ""; | |
5 | int firstCount = 0; | |
6 | String secondFace = ""; | |
7 | int secondCount = 0; | |
8 | for (int i = 0; i < hand.length; i++) { | |
9 | if(hand[i].face != "*" ){ | |
10 | if(firstFace == ""){ | |
11 | firstFace = hand[i].face; | |
12 | firstCount = 1; | |
13 | } | |
14 | else if(hand[i].face != firstFace && secondFace != ""){ | |
15 | if(hand[i].face != secondFace){ | |
16 | return false; | |
17 | } | |
18 | else{ | |
19 | secondCount++; | |
20 | if(secondCount > 3){ | |
21 | return false; | |
22 | } | |
23 | } | |
24 | } | |
25 | else if(hand[i].face != firstFace && secondFace == ""){ | |
26 | secondFace = hand[i].face; | |
27 | secondCount = 1; | |
28 | } | |
29 | else{ | |
30 | firstCount++; | |
31 | if(firstCount > 3){ | |
32 | return false; | |
33 | } | |
34 | } | |
35 | } | |
36 | } | |
37 | return true; | |
38 | } | |
39 | ||
40 | public static Card[] hand = new Card[5]; | |
41 | ||
42 | public static void main(String[] args) { | |
43 | String[] faces = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}; | |
44 | String[] suits = {"♣", "♦", "♥", "♠"}; | |
45 | Card[] cards = new Card[57]; | |
46 | cards[0] = new Card("*", ""); | |
47 | cards[1] = new Card("*", ""); | |
48 | cards[2] = new Card("*", ""); | |
49 | cards[3] = new Card("*", ""); | |
50 | cards[4] = new Card("*", ""); | |
51 | int p = 5; | |
52 | for(int i = 0; i < suits.length; i++){ | |
53 | for(int j = 0; j < faces.length; j++){ | |
54 | cards[p++] = new Card(faces[j], suits[i]); | |
55 | } | |
56 | } | |
57 | int fullHouseCount = 0; | |
58 | for(int i = 0; i < cards.length - 4; i++){ | |
59 | for(int j = i + 1; j < cards.length - 3; j++){ | |
60 | for(int k = j + 1; k < cards.length - 2; k++){ | |
61 | for(int l = k + 1; l < cards.length - 1; l++){ | |
62 | for(int m = l + 1; m < cards.length; m++){ | |
63 | Card[] hand = new Card[5]; | |
64 | hand[0] = cards[i]; | |
65 | hand[1] = cards[j]; | |
66 | hand[2] = cards[k]; | |
67 | hand[3] = cards[l]; | |
68 | hand[4] = cards[m]; | |
69 | if(isFullHouse(hand)){ | |
70 | fullHouseCount++; | |
71 | System.out.printf("( %s %s %s %s %s )", hand[0], hand[1], hand[2], hand[3], hand[4]); | |
72 | } | |
73 | } | |
74 | } | |
75 | } | |
76 | } | |
77 | } | |
78 | System.out.printf("%d full houses", fullHouseCount); | |
79 | } | |
80 | } | |
81 | ||
82 | ||
83 | public class Card { | |
84 | String face; | |
85 | String suit; | |
86 | ||
87 | public Card(String f, String s){ | |
88 | this.face = f; | |
89 | this.suit = s; | |
90 | } | |
91 | ||
92 | public String toString(){ | |
93 | return this.face + this.suit; | |
94 | } | |
95 | } |