要编一个程序,从键盘中选择5个0-51的数,Club的数是从0-12,Diamond是从13-25,Hearts是从26-38,Spades是从39-51,每个部分都是13个数,如果这五个数都属于一个部分例如:3,2,5,4,7那么就说这五个数是Flush,如果是顺牌就叫Straight,如果是同花顺就是Royal Straight.这个怎么编呢,好像要便各子程序调用看看这5个数是属于什么情况? 八爪鱼你能帮我看看吗?我头大了,也希望大家能给个Code.我是菜鸟学习中,跪谢。

解决方案 »

  1.   


    import java.util.Arrays;public class Test {
    public static void main(String[] args) {
    int[] poker = new int[]{14,3,4,5,6};

    if(isStraight(poker)&&isFlush(poker)){
    System.out.println("是同花顺");
    }else if(isStraight(poker) && !isFlush(poker)){
    System.out.println("是顺子");
    }else if(!isStraight(poker)&&isFlush(poker)){
    System.out.println("是同花");
    }else{
    System.out.println("什么都不是");
    }
    }

    /*
     * 是不是顺子
     * */
    public static boolean isStraight(int[] poke){
    int[] temp = new int[poke.length];
    for(int i=0;i<poke.length;i++){
    temp[i] = poke[i]%13;
    }
    Arrays.sort(poke);//排序
    if( (temp[temp.length-1] - temp[0]) == 
    (temp.length-1)){
    return true;
    }
    return false;
    }

    /*
     * 是不是同花
     * */
    public static boolean isFlush(int[] poke){
    int i = poke[0]/13;
    for(int n=1;n<poke.length;n++){
    if(poke[n]/13 == i){
    }else{
    return false;
    }
    }
    return true;
    }
    }
      

  2.   

    如果是2 15,28,3,16这样的就是Full House三个数是一样的,两个数是一样的。如果只有两个数是一样的,叫Pair。如果有两个两个数一样的叫Two Pair。 如果把随机从0-51里面选五个不同的数,从键盘上输入两个不同的数做比较,同花顺》顺牌》Full House》Two Pair》Pair 然后输出赢家。应该怎么编呢?告送我怎么加分,我加分给大家,跪谢了!!!
      

  3.   

    在管理帖子里有加分,但是不知道怎么提交,没找到提交的Button
      

  4.   


    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.HashSet;public class Test {
        public static void main(String[] args) {
            //int[] poker = new int[]{14, 3, 4, 5, 6};
            int[] poker = new int[]{16, 3, 29, 5, 6};        if (isStraight(poker) && isFlush(poker)) {
                System.out.println("是同花顺");
            } else if (isStraight(poker) && !isFlush(poker)) {
                System.out.println("是顺子");
            } else if (!isStraight(poker) && isFlush(poker)) {
                System.out.println("是同花");
            } else if(isFullHouse(poker)==0){
                System.out.println("4张一样");
            } else if(isFullHouse(poker)==1){
                System.out.println("3张一样+1对");
            } else if(isFullHouse(poker)==2){
                System.out.println("3张一样+无对");
            } else if(isFullHouse(poker)==3){
                System.out.println("2对");
            } else if(isFullHouse(poker)==3){
                System.out.println("1对");
            } else{
                System.out.println("什么都不是");
            }
        }    /* 
         *   是不是顺子 
         *   */
        public static boolean isStraight(int[] poke) {
            HashSet temp=new HashSet();
            for (int i = 0; i < poke.length; i++) {
                temp.add(new Integer(poke[i] % 13));
            }
            if (temp.size()!=5) {
                return false;
            }
            return true;
        }    /* 
         *   是不是同花 
         */
        public static boolean isFlush(int[] poke) {
            int i = poke[0] / 13;
            for (int n = 1; n < poke.length; n++) {
                if (poke[n] / 13 == i) {
                } else {
                    return false;
                }
            }
            return true;
        }
        
        /* 
         *   是不是Full House 
         */
        public static int isFullHouse(int[] poke) {
            HashMap temp=new HashMap();
            for (int i = 0; i < poke.length; i++) {
                Integer privateValue=new Integer(poke[i] % 13);
                Integer currentCount=(Integer) temp.get(privateValue);
                int count=currentCount==null?1:currentCount.intValue()+1;
                temp.put(new Integer(poke[i] % 13),new Integer(count));
            }
            if (temp.size()==2) {
                //这种情况,任意找一个根据Map中的value即可判断
                               //Map中的内容会是1:4;2:1这种
                Integer count=(Integer) temp.get(new Integer(poke[0]%13));
                //4张一样的
                if(count.intValue()==1)
                    return 0;
                //3张一样的+一对    
                     //Map中的内容会是1:3;2:2这种
                else
                    return 1;
            }else if (temp.size()==3) {
                            //Map中的内容会是1:2;2:2;3:1这种
                for(int i=0;i<poke.length;i++){
                    Integer count=(Integer) temp.get(new Integer(poke[i]% 13));
                    if(count.intValue()==2){
                        //二对
                        return 3;
                    } 
                }
                            //Map中的内容会是1:3;2:1;3:1这种
                //3张一样的,无对
                return 2;
            }else if (temp.size()==4) {
                //一对
                return 4;
            }else{
                //杂牌,比大小
                return 5;
            }
        }
    }暂时这样吧,用了HashMap/HashSet/ 
    你学习一下吧, 
    不过程序中可能有别的问题,你好好看看吧,没有时间了,要上班了!
      

  5.   

    另外我用的是JDK1.4所以写法与1.5有些差别,你自己注意改一下,
    但是1.5下不会出错
      

  6.   

    程序太多了,我已经通过MSN发给你了。