首页 > 学院 > 开发设计 > 正文

扑克牌的发牌程序(用伪随机数实现)

2019-11-17 05:33:19
字体:
来源:转载
供稿:网友
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
int *insertsort(int sort[],int k)     /*插入排序*/
{
  int i,j;
 
  for(i=k-2;i>=0;i--)
   {
     sort[k-1]=sort[i];
     j=i+1;
     while(sort[k-1]>sort[j])
       {
        sort[j-1]=sort[j];
        j++;
       }
      sort[j-1]=sort[k-1];
   }
 return sort;
}void output(int card[],int n)         /*转换输出函数,将生成的随机数转换成扑克牌输出*/
{
 int i,j; textbackground(1);           
            
 for(i=0;i<n-1;i++) {
  
   switch(card[i]/26)
   {
     case 0:
        switch((card[i]+4)/2){
              case 2:
              case 3:
              case 4:
              case 5:               
              case 6:                
              case 7:                
              case 8:               
              case 9:               
              case 10:
                 PRintf("%c%d",3,(card[i]+4)/2);break;                             
              case 11:
                 printf("%cJ",3);break;
              case 12:
                 printf("%cQ",3);break;
              case 13:
                 printf("%cK",3);break;
              case 14:
                 printf("%cA",3);break;
        }
     case 1:
        switch((card[i]-26+4)/2){
              case 2:
              case 3:
              case 4:
              case 5:
              case 6:
              case 7:
              case 8:
              case 9:
              case 10:
                 printf("%c%d",4,(card[i]-26+4)/2);break;
              case 11:
                 printf("%cJ",4);break;
              case 12:
                 printf("%cQ",4);break;
              case 13:
                 printf("%cK",4);break;
              case 14:
                 printf("%cA",4);break;
        }       
     case 2:
        switch((card[i]-52+4)/2){
              case 2:
              case 3:
              case 4:
              case 5:
              case 6:
              case 7:
              case 8:
              case 9:
              case 10:
                 printf("%c%d",5,(card[i]-52+4)/2);break;
              case 11:
                 printf("%cJ",5);break;
              case 12:
                 printf("%cQ",5);break;
              case 13:
                 printf("%cK",5);break;
              case 14:
                 printf("%cA",5);break;
        }       
     case 3:
        switch((card[i]-78+4)/2){
              ca


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表