• 扑克牌2


    随机发牌:去掉大小王,发给4个人,每人发13张,要求分四行,并按花色和牌点排序。样例:SAK9  HKT9876  DQ32  CJ。

     1 #include<iostream>
     2 #include<cstdlib>
     3 using namespace std;
     4 const char puke[]="123456789TJQK";//转换数组
     5 const char color[] = "SHDC";//四种花色
     6 void outpuke(int i ,int &j, int a[4][13], int top)
     7 //第i个人的出牌函数,j表示当前第几张牌,top代表花色的数字界限(例如:黑桃top=13,红桃top=26)
     8 {
     9     if(a[i][j]<top)cout<<color[top/13-1];//color为了省事直接用top/13-1即可
    10     while(a[i][j]<top&&j<13)
    11     {
    12         cout<<puke[a[i][j++]%13];
    13     }
    14     cout<<" ";
    15 }
    16 int main()
    17 {
    18     int people[4][13];//四个人,每人13张牌
    19     int num[4] = {0,0,0,0};//四个人的当前手牌数
    20     srand(time(NULL));
    21     for(int i = 0 ; i < 52 ; i++)//随机发牌
    22     {
    23         int tem = rand()%4;
    24         while(1)
    25         {
    26             if(num[tem]<13)break;
    27             else tem = rand()%4;
    28         }
    29         if(tem==0)people[tem][num[0]++] = i;
    30         if(tem==1)people[tem][num[1]++] = i;
    31         if(tem==2)people[tem][num[2]++] = i;
    32         if(tem==3)people[tem][num[3]++] = i;
    33     }
    34     for(int peo=0; peo < 4 ; peo ++ )
    35     {
    36         cout<<""<<peo+1<<"个人的手牌: ";
    37         int j = 0;
    38         for(int i = 1 ; i < 5 ; i ++)
    39         {
    40             outpuke(peo,j,people,13*i);
    41         }
    42         cout<<endl;
    43     }
    44 }
  • 相关阅读:
    2019暑假集训 windy数
    2019暑假集训 数字游戏
    2019暑假集训 周年纪念晚会
    2019暑假集训 加分二叉树
    0013-求圆柱体体积
    0012-求滑动距离
    0011-绝对值函数
    0010-温度转换
    0009-乘法问题
    0008-三位数倒序问题
  • 原文地址:https://www.cnblogs.com/Duskcl/p/3949825.html
Copyright © 2020-2023  润新知