Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class StraightFlush {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String inputLine = input.nextLine().replaceAll("([\\', ']+)"," ");
- String[] inputCards=inputLine.split(" ");
- if (inputCards.length<5){
- System.out.println("No Straight Flushes");
- return;
- }
- String[] faces = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
- char[] suits = {'C','D','H','S'};
- int[] ranks = {0,4,8,12,16,20,24,28,32,36,40,44,48};
- Map<String,Integer> deck = new HashMap<>();
- for (int i = 0; i < faces.length; i++){
- for (int j = 0, k = 0; j < suits.length; j++,k++){
- deck.put(faces[i]+suits[j], ranks[i]+k);
- }
- }
- Map<Integer,String> inputCardsMap = new HashMap<>();
- for (int i = 0; i < inputCards.length; i++){
- inputCardsMap.put(deck.get(inputCards[i]),inputCards[i]);
- }
- boolean straightFlushFound=false;
- for (int i = 0; i < inputCards.length; i++){
- String temp = inputCards[i];
- int current = deck.get(temp);
- int next = deck.get(temp)+4;
- if (inputCardsMap.containsKey(next)){
- next+=4;
- if (inputCardsMap.containsKey(next)){
- next+=4;
- if (inputCardsMap.containsKey(next)){
- next+=4;
- if (inputCardsMap.containsKey(next)){
- System.out.printf("[%s, %s, %s, %s, %s]\n",
- inputCardsMap.get(current),
- inputCardsMap.get(current+4),
- inputCardsMap.get(current+8),
- inputCardsMap.get(current+12),
- inputCardsMap.get(current+16));
- straightFlushFound=true;
- }
- }
- }
- }
- }
- if (straightFlushFound==false){
- System.out.println("No Straight Flushes");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment