zoukankan      html  css  js  c++  java
  • 纸牌排序

    import java.util.*;

    public class Test {

    public static void main(String[] args) {

    Random rnd = new Random();

    int Cards[][] = new int[13][4];//检测牌是否会重复

    int Cardss[][] = new int[13][4];//按牌的大小给每张牌赋值,例如方块3等于1,黑桃2等于52,

    int t = 1;

    //赋值

    for (int m = 0; m < 13; m++)

    {

    for (int n = 0; n < 4; n++)

    {

    Cardss[m][n] = t;

    t++;

    }

    }

    //原牌

    for (int m = 0; m < 4; m++)

    {

    for (int n = 0; n < 13; n++)

    {

    Card Ca = new Card(n, m);

    System.out.print(Ca.display() + " ");

    }

    System.out.println();

    }

    System.out.println();

    System.out.println();

    int a, b, sum = 0,r=0,l=0;

    String[][] str = new String[4][53];

    while (sum!= 52) //牌的数量到52张的时候就退出循环

    {

    a = rnd.nextInt(13);//控制点数

    b = rnd.nextInt(4);//控制花色

    if (Cards[a][b] == 0)//当二维数组这个位置没有出现对应的牌时,才可进入下步操做

    {

    Cards[a][b]=1;//标记这张牌已出现过了

    Card Ca = new Card(a, b);//生成一个新对象

    System.out.print(Ca.display() + " ");

    sum++;//统计牌数

    l=Cardss[a][b]; //把这张牌对应的值赋值给l

    str[r][l]=Ca.display();

    if (sum % 13 == 0)

    {

    System.out.println();

    r++;

    }

    }

    }

    //整理牌

    System.out.println();

    System.out.println();

    for(r=0;r<4;r++)

    {

    for(l=0;l<53;l++)

    {

    if(str[r][l]!=null)

    {

    System.out.print(str[r][l]+" ");

    }

    }

    System.out.println();

    }

    }

    }

    class Card

    {

    int face;// 点数 3(0) 4 5 6 7 8 9 10 J(8) Q(9) K(10) A(11) 2(12)

    int suit;// 花色 方块(0) 梅花(1) 红桃(2) 黑桃(3)

    public Card(int f, int s)

    {

    face = f;

    suit = s;

    }

    public String display()

    {

    String s = ""; // 花色

    if (suit == 0)

    s = "♦️";

    else if (suit == 1)

    s = "♣️";

    else if (suit == 2)

    s = "♥️";

    else if (suit == 3)

    s = "♠️";

    String f = ""; // 点数

    if (face >= 0 && face <= 7)

    f = face + 3 + "";

    else if (face == 8)

    f = "J";

    else if (face == 9)

    f = "Q";

    else if (face == 10)

    f = "K";

    else if (face == 11)

    f = "A";

    else if (face == 12)

    f = "2";

    return s + f;

    }

    }

  • 相关阅读:
    BZOJ 1977: [BeiJing2010组队]次小生成树 Tree( MST + 树链剖分 + RMQ )
    BZOJ 2134: 单选错位( 期望 )
    BZOJ 1030: [JSOI2007]文本生成器( AC自动机 + dp )
    BZOJ 2599: [IOI2011]Race( 点分治 )
    BZOJ 3238: [Ahoi2013]差异( 后缀数组 + 单调栈 )
    ZOJ3732 Graph Reconstruction Havel-Hakimi定理
    HDU5653 Bomber Man wants to bomb an Array 简单DP
    HDU 5651 xiaoxin juju needs help 水题一发
    HDU 5652 India and China Origins 并查集
    HDU4725 The Shortest Path in Nya Graph dij
  • 原文地址:https://www.cnblogs.com/suHDH/p/8900160.html
Copyright © 2011-2022 走看看