Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- /**
- * Created by Ekuseru on 2015/04/26.
- */
- public class HappyFamily {
- public static void main(String[] args){
- String[] family ={"A", "B", "C","D","E","F"};
- String[] job = {" 1", "\'2", "\'3", "\'4"};
- int count = 0;
- ArrayList<String> deck = new ArrayList<String>();
- for (int i = 0; i < family.length; i++) {
- for (int j = 0; j < job.length; j++) {
- deck.add(family[i] + job[j]);
- }
- }
- //draw random 10 cards
- ArrayList<String> hand = new ArrayList<String>();
- Collections.shuffle(deck);
- for (int i = 0; i < 20; i++) {
- hand.add(deck.get(0));
- deck.remove(0);
- }
- Collections.sort(hand);
- String[] h = hand.toArray(new String[hand.size()]);
- hand.toArray(h);
- for(int i=0; i<h.length-4;i++){
- String t1 = h[i];
- String t2 = h[i+3];
- t1 = t1.split("('|\\s)")[0];
- t2 = t2.split("('|\\s)")[0];
- count = t1.equals(t2)?count+1: count;
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement