首页 > 试题广场 >

德州扑克问题:一副牌中发五张扑克牌给你:让你判断数字的组成,

[问答题]

德州扑克问题 一副牌中发五张扑克牌给你:让你判断数字的组成:

有以下几种情况:

 1:四条:即四张一样数值的牌(牌均不论花色)2:三条带 一对

 3:三条带两张不相同数值的牌

 4:两对

 5:顺子  包括 10,J,Q,K,A

6:什么都不是

 7:只有一对

编程实现以上功能。
#include "stdio.h"
void sort(int data[], int n)
{
    int temp = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (data[i] < data[j])
            {
                temp = data[i];
                data[i] = data[j];
                data[j] = temp;
            }
        }
    }
}
void test(int a[], int len)
{
    int *b = new int[len];
    int count = 0;
    bool temp = false;
    for (int i = 0; i < len; i++)
    {
        b[i] = a[i];
    }
    sort(b, 5);
    for (i = 0; i < len - 1; i++)
    {
        if (b[i] == b[i + 1])
            count++;
    }
    switch (count)
    {
    case 0:
        if (b[0] - b[4] == 4 && b[0] - b[3] == 3 && b[0] - b[2] == 2 && b[0] - b[1] == 1)
        {
            printf("顺子");
        }
        else
            printf("什么都不是");
        break;
    case 1:
        printf("只有一对");
        break;
    case 2:
        for (i = 0; i < 3; i++)
        {
            if (b[i] == b[i + 2])
            {
                printf("三条带两张不相同数值的牌");
                temp = true;
                break;
            }
        }
        if (!temp)
        {
            printf("两对");
        }
        break;
    case 3:
        if (b[1] == b[3])
            printf("四条:即四张一样数值的牌");
        else
            printf("三条带一对");
        break;
    }
}
main()
{
    int a[5] = {3, 3, 3, 3, 12};
    test(a, 5);
    return 0;
}

发表于 2014-11-13 23:57:31 回复(0)
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            int[] num = new int[13];
            int[] aa = new int[5];
            for (int i = 0; i < 5; i++) {
                int temp = sc.nextInt();
                aa[i] = temp;
                num[temp - 1]++;
            }

            Arrays.sort(num);
            Arrays.sort(aa);

            if (num[12] == 4) {
                System.out.println(1);
            } else if (num[12] == 3 && num[11] == 2) {
                System.out.println(2);
            } else if (num[12] == 3 && num[11] == 1) {
                System.out.println(3);
            } else if (num[12] == 2 && num[11] == 2) {
                System.out.println(4);
            } else if (num[12] == 2 && num[11] == 1) {
                System.out.println(7);
            } else {
                boolean flag = true;
                for (int i = 1; i < 5; i++) {
                    if (aa[i] != aa[0] + i) {
                        System.out.println(6);
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    System.out.println(5);
                }
            }

        }

    }

}
发表于 2020-03-31 22:39:23 回复(0)
import java.util.Arrays; import java.util.HashSet; public class Test2 { /**  * 链接:https://www.nowcoder.com/questionTerminal/d9385db532594b1789eecf198a99bef3?mutiTagIds=570_578&orderByHotValue=1  来源:牛客网   德州扑克问题 :一副牌中发五张扑克牌给你:让你判断数字的组成:  有以下几种情况:   1:四条:即四张一样数值的牌(牌均不论花色)2:三条带 一对   3:三条带两张不相同数值的牌   4:两对   5:顺子  包括 10JQKA  6:什么都不是   7:只有一对  */  public  static  final int pk[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; public  static  final int pks[] = {1,1,1,1,1}; public static int[] fenpei() { int select[] = new int[5]; //获取5张牌  for(int i = 0;i<5;i++){ int dex = (int) (Math.random()*pk.length); select[i]=pk[dex];
        } return select;
    } private static void lj (int [] arg){ Arrays.sort(arg); if(arg[0]==arg[4]){ //5张牌一样了,重新分配  arg = fenpei();
        } HashSet<Integer> hashSet = new HashSet<Integer>(); for(int i = 0;i<arg.length;i++){ hashSet.add(arg[i]); System.out.print(arg[i]+",");
        } if(arg[0]==arg[3] || arg[1]==arg[4]){ System.out.print("四条:即四张一样数值的牌(牌均不论花色)");
        }else if (arg[0] == arg[2] || arg[1] == arg[3] ||arg[2] ==arg[4]) { if(hashSet.size() == 2){ System.out.print("三条带 一对");
            }else{ System.out.print("三条带两张不相同数值的牌");
            }
        }else if(hashSet.size() == 3){ System.out.print("两对");
        }else if (hashSet.size() ==4){ System.out.print("只有一对");
        }else if(arg[0]+1 == arg[1]&&arg[1]+1==arg[2]&&arg[2]+1==arg[3]&&arg[3]+1==arg[4]){ System.out.print("顺子");
        }else if(arg[1]+1==arg[2]&&arg[2]+1==arg[3]&&arg[3]+1==arg[4]&&arg[4]+1 == 14){ System.out.print("顺子");
        }else{ System.out.print("什么都不是");
        } return;
    } public static void main(String[] args) { lj(pks);
    }
}//这里JQKA分别用11,12,13,1表示
发表于 2017-12-25 15:11:41 回复(0)
public class PuKe { public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);  String next = scanner.next();  String [] pukeArray = next.split(",");  int [] arr = new int[5];  for(int i =0;i<5;i++){ if(pukeArray[i].equals("J")){
                pukeArray[i] = "11";  } if(pukeArray[i].equals("Q")){
                pukeArray[i] = "12";  } if(pukeArray[i].equals("K")){
                pukeArray[i] = "13";  } if(pukeArray[i].equals("A")){
                pukeArray[i] = "14";  }
            arr[i] = Integer.valueOf(pukeArray[i]);  } qiuckSort( arr,0,4); //这里可以使用冒泡简单的进行排序  //1.四条  if(arr[0]==arr[3] || arr[1] == arr[4]){
            System.out.println("1:四条");  } else if((arr[0] == arr[1] && (arr[2]==arr[3]) && (arr[3]==arr[4])) || (arr[3] == arr[4] && (arr[0]==arr[1]) && (arr[1]==arr[2]))){
            System.out.println("2:三带一对");  }else if((arr[0]==arr[1]  && arr[2]==arr[3]  && arr[3]!=arr[4])||
                (arr[0]!=arr[1]  && arr[1]==arr[2]  && arr[3]==arr[4])||
                 (arr[0]==arr[1]  && (arr[1] !=arr[2]  && arr[3]==arr[4]))){
            System.out.println("4:两对");  }else if((arr[0]==arr[1] && arr[1]==arr[2] && arr[3]!=arr[4])||
                (arr[1]==arr[2] && arr[2]==arr[3] && arr[1]!=arr[0] && arr[3]!=arr[4] )){
            System.out.println("3:三条带两张不相同数值的牌");  }else if(arr[4] - arr[0] == 4){
            System.out.println("5:顺子  包括 10,J,Q,K,A");  }else if((arr[0] == arr[1]) || (arr[1] == arr[2]) || (arr[2] == arr[3]) || (arr[3] == arr[4])){
            System.out.println("7:只有一对");  }else{
            System.out.println("6:什么都不是");  }

    } public static void qiuckSort(int array [],int low,int high){ int i = low,j = high;  int key = array[(low + high) / 2];  int temp ;  do{ while(array[i] < key){i++;} while(array[j] > key){j--;} if(i <= j){
                temp = array[j];  array[j] = array[i];  array[i] = temp;  i++;  j--;  }
        }while(i <= j);  if(low < j){ qiuckSort(array , low, j); } if(high > i){ qiuckSort(array , i, high); }
    }
}
发表于 2015-08-15 22:46:39 回复(0)