svetlozar_kirkov

Straight Flush

Feb 4th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5. public class StraightFlush {
  6.    
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         String inputLine = input.nextLine().replaceAll("([\\', ']+)"," ");
  10.         String[] inputCards=inputLine.split(" ");
  11.         if (inputCards.length<5){
  12.             System.out.println("No Straight Flushes");
  13.             return;
  14.         }
  15.         String[] faces = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
  16.         char[] suits = {'C','D','H','S'};
  17.         int[] ranks = {0,4,8,12,16,20,24,28,32,36,40,44,48};
  18.         Map<String,Integer> deck = new HashMap<>();
  19.                
  20.         for (int i = 0; i < faces.length; i++){
  21.             for (int j = 0, k = 0; j < suits.length; j++,k++){
  22.                 deck.put(faces[i]+suits[j], ranks[i]+k);
  23.             }
  24.         }
  25.        
  26.         Map<Integer,String> inputCardsMap = new HashMap<>();
  27.        
  28.         for (int i = 0; i < inputCards.length; i++){
  29.             inputCardsMap.put(deck.get(inputCards[i]),inputCards[i]);
  30.         }
  31.        
  32.         boolean straightFlushFound=false;
  33.         for (int i = 0; i < inputCards.length; i++){
  34.             String temp = inputCards[i];
  35.             int current = deck.get(temp);
  36.             int next = deck.get(temp)+4;
  37.             if (inputCardsMap.containsKey(next)){
  38.                 next+=4;
  39.                 if (inputCardsMap.containsKey(next)){
  40.                     next+=4;
  41.                     if (inputCardsMap.containsKey(next)){
  42.                         next+=4;
  43.                         if (inputCardsMap.containsKey(next)){
  44.                             System.out.printf("[%s, %s, %s, %s, %s]\n",
  45.                                     inputCardsMap.get(current),
  46.                                     inputCardsMap.get(current+4),
  47.                                     inputCardsMap.get(current+8),
  48.                                     inputCardsMap.get(current+12),
  49.                                     inputCardsMap.get(current+16));
  50.                             straightFlushFound=true;
  51.                         }
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.         if (straightFlushFound==false){
  57.             System.out.println("No Straight Flushes");
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment