// Arup Guha
// 7/22/03
// Solution to 2003 BHCSI Homework #9: Three Card Dud.

import java.io.*;
import java.util.*;

public class ThreeCard {

  final static char[] suits = {'C','D','H','S'};

  public static void main(String[] args) throws IOException {

    BufferedReader stdin = new BufferedReader
				(new InputStreamReader(System.in));

    // Loops until user wants to quit.
    // Note: This loop can ALSO be controlled by checking the character
    //       the user entered. I did this to illustrate the use of a
    //       break statement.
    while (true) {

      int val1, val2, val3;
      Random r = new Random();

      // Generates three random cards.
      val1 = Math.abs(r.nextInt()%52);

      // Make sure the second is different than the first.
      val2 = val1;
      while (val2 == val1) 
        val2 = Math.abs(r.nextInt()%52);

      // Make sure the third is different as well.
      val3 = val2;
      while (val3 == val2 || val3 == val1)
        val3 = Math.abs(r.nextInt()%52);
  
      // Print out all three cards.
      System.out.println("The three generated cards are:");
      printCard(val1);
      System.out.println();
      printCard(val2);
      System.out.println();
      printCard(val3);
      System.out.println();
        
      // Score each card, and add bonuses if necessary.
      int score = 0;
      score += scoreCard(val1) + scoreCard(val2) + scoreCard(val3);
  
      if (suitBonus(val1,val2,val3))
        score += 15;

      if (kindBonus(val1, val2, val3))
        score += 100;

      // Output score.
      System.out.println();
      System.out.println("Your score: "+score);

      // Check if user wants to score another hand. Stop if not.
      System.out.println("Want to score another random hand?");
      char ans = stdin.readLine().charAt(0);
      if (ans != 'y' && ans != 'Y')
        break;
     }
  }

  public static int scoreCard(int val) {

    // Takes care of normal case.
    int value = val%13 + 1;
    if (value >= 2 && value <= 10)
      return value;

    // Face cards.
    else if (value > 10)
      return 10;

    // Ace.
    else
      return 15;
  }

  public static boolean suitBonus(int val1, int val2, int val3) {

    // Calculate suits and see if they are all equal.
    int value1 = val1/13;
    int value2 = val2/13;
    int value3 = val3/13;
    return (value1 == value2 && value2 == value3);
  }

  public static boolean kindBonus(int val1, int val2, int val3) {

    // Calculate kinds and see if they are all equal.
    int value1 = val1%13;
    int value2 = val2%13;
    int value3 = val3%13;
    return (value1 == value2 && value2 == value3);
  }

  public static void printCard(int val) {

    // Assign suit using static array of values.
    char suit = suits[val/13];

    // Calculate the kind, first by value.
    int value = val%13 + 1;

    // Convert this int to a char, go through all non-numeric cards
    // on a case by case basis.
    char kind;
    if (value >=2 && value <=10)
      kind = (char)('0'+value);
    else if (value == 1)
      kind = 'A';
    else if (value == 11)
      kind = 'J';
    else if (value == 12)
      kind = 'Q';
    else 
      kind = 'K';
    
    // Print out card.
    System.out.print(kind+" "+suit);
  }
  
}
