zoukankan      html  css  js  c++  java
  • 扑克牌算法(2)

    核心步骤:利用随机数给数组赋值。

     1 public class wicket_2 {
     2     public static void main(String[] args) {
     3         String []s=new String[]{"黑桃","红桃","梅花","方块"};
     4         String []sign=new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
     5         final int N=52;
     6         int card[]=new int[N];
     7         for(int i=0;i<card.length;i++) {
     8             card[i]+=i;
     9         }
    10         System.out.println("开始时牌顺序:");
    11         for(int i=0;i<card.length;i++) {
    12             System.out.printf("  %s%s",s[card[i]/13],sign[card[i]%13]);
    13             if((i+1)%13==0) {
    14                 System.out.println();
    15             }
    16         }
    17         //模拟洗牌
    18         for(int i=0;i<card.length;i++) {
    19             card[i]=(int)((Math.random())*52);
    20         }
    21         System.out.println("洗牌后的顺序为:");
    22         for(int i=0;i<card.length;i++) {
    23             System.out.printf("  %s%s",s[card[i]/13],sign[card[i]%13]);
    24             if((i+1)%13==0) {
    25                 System.out.println();
    26             }
    27         }
    28     }
    29 }

    运算结果:

  • 相关阅读:
    P1092 虫食算
    P1040 加分二叉树
    cfER76 abcd
    cf599 div2 a/b1/b2/c
    AtCoder Contest 144 DE
    Round G 2019
    luogu3084 Photo 单调队列优化DP
    luogu4234 最小差值生成树
    luogu1373 小a和uim之大逃离
    luogu1070 道路游戏 单调队列
  • 原文地址:https://www.cnblogs.com/mianyang0902/p/10805233.html
Copyright © 2011-2022 走看看