Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _4_PokerStraight {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- int givenWeight = scan.nextInt();
- int countStraightHands = 0;
- if (givenWeight >= 555 && givenWeight <= 1920) {
- countStraightHands = getTheCountOfStraightHandsWithGivenWeight(givenWeight);
- }
- System.out.println(countStraightHands);
- }
- private static int getTheCountOfStraightHandsWithGivenWeight(int weight) {
- // TODO Auto-generated method stub
- int countStraights = 0;
- int face, currentWeight;
- int suit1, suit2, suit3, suit4, suit5;
- for (face = 1; face <= 10; face++) {
- for (suit1 = 1; suit1 <= 4; suit1++) {
- for (suit2 = 1; suit2 <= 4; suit2++) {
- for (suit3 = 1; suit3 <= 4; suit3++) {
- for (suit4 = 1; suit4 <= 4; suit4++) {
- for (suit5 = 1; suit5 <= 4; suit5++) {
- currentWeight = calculateTheWeightOfCurrentStraight(
- face, suit1, suit2, suit3, suit4, suit5);
- if (currentWeight == weight) {
- countStraights++;
- }
- }
- }
- }
- }
- }
- }
- return countStraights;
- }
- private static int calculateTheWeightOfCurrentStraight(int face, int s1,
- int s2, int s3, int s4, int s5) {
- // TODO Auto-generated method stub
- int totalWeight = (10 * face) + (20 * (face + 1)) + (30 * (face + 2))
- + (40 * (face + 3)) + (50 * (face + 4));
- totalWeight += s1 + s2 + s3 + s4 + s5;
- return totalWeight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement