Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Scanner;
- public class Problem04_StraightFlush {
- @SuppressWarnings("resource")
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- String[] input = scn.nextLine().split("\\W+");
- HashMap<String, ArrayList<String>> cards = new HashMap<>();
- for (int i = 0; i < input.length; i++) {
- String face = input[i].substring(0, input[i].length() - 1);
- String suit = input[i].substring(input[i].length() - 1);
- if (!cards.containsKey(suit)) {
- cards.put(suit, new ArrayList<String>());
- cards.get(suit).add(face);
- }
- else {
- cards.get(suit).add(face);
- }
- }
- boolean found = false;
- for (String suit : cards.keySet()) {
- if (cards.get(suit).size() > 4) {
- for (String card : cards.get(suit)) {
- if (!card.equals("J") && !card.equals("Q") && !card.equals("K") && !card.equals("A")) {
- ArrayList<String> hand = getHand(card);
- if (cards.get(suit).containsAll(hand)) {
- System.out.print("[");
- for (int i = 0; i < hand.size(); i++) {
- if (i == 4) {
- System.out.print(hand.get(i) + suit + "]");
- }
- else {
- System.out.print(hand.get(i) + suit + ", ");
- }
- }
- System.out.println();
- found = true;
- }
- }
- }
- }
- }
- if (!found) {
- System.out.println("No Straight Flushes");
- }
- }
- public static ArrayList<String> getHand(String card) {
- ArrayList<String> cards = new ArrayList<String>
- (Arrays.asList("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"));
- ArrayList<String> returnList = new ArrayList<String>();
- int index = Integer.parseInt(card) - 2;
- returnList = new ArrayList<>(cards.subList(index, index + 5));
- return returnList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement