回 帖 发 新 帖 刷新版面

主题:[讨论]这是我写的一个发牌程序   请各位评价一下

各位   这个发牌程序效率可能不高   希望各位指点一下 

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void printary(int oary[],int size);
int main (void)
{
    int ary[52];
    int ary1[13];
    int ary2[13];
    int ary3[13];
    int ary4[13];
    int i;
    int p=0;
    int q=0;
    int r=0;
    int s=0;
    int m;
    
  for(i=0;i<52;i++)
  {
  ary[i]=i+1;
  }
  srand((unsigned)time(NULL));
  for(i=0;i<52;i++)
  {
  m=(rand()%52+1)%4;
     switch(m)
    {
       case 0:  
            if(p<13)
              {
              ary1[p]=i;
              p++;
              }
             else
              if(q<13)
               {
                 ary2[q]=i;
                 q++;
               }
               else
                if(r<13)
                 {
                   ary3[r]=i;
                   r++;
                   }
                   else
                   ary4[12]=i;
           break;
      case 1: 
           if(q<=12)
           {
             ary2[q]=i;
             q++;
           }
           else
             if(r<13)
             {
               ary3[r]=i;
               r++;
               }
              else
              if(s<13)
              {
                ary4[s]=i;
                s++;
              }
                else
                ary1[12]=i;
              break;
     case 2:  
              if(r<13)
              {
              ary3[r]=i;
              r++;
              }
              else
                if(s<13)
                 {
                  ary4[s]=i;
                  s++;
                  }
                  else
                  if(p<13)
                  {
                    ary1[p]=i;
                     p++;
                    }
                    else
                    ary2[12]=i;
               break;
       case 3: 
                 if(s<13)
                 {
                 ary4[s]=i;
                 s++;
                 }
                 else
                   if(p<13)
                   {
                    ary1[p]=i;
                    p++;
                    }
                    else
                    if(q<12)
                    {
                     ary2[q]=i;
                     q++;
                     }
                     else
                     ary3[12]=i;
             break;
       }
  }
printf("NORTH\n");
printary(ary1,13);
printf("\nEAST\n");
printary(ary2,13);
printf("\nSOUTH\n");
printary(ary3,13);
printf("\nWEST\n");
printary(ary4,13);
getchar(); 
return 0;
}

void printary(int oary[],int size)
{
    int i;
    for(i=0;i<size;i++)
    printf("%3d",oary[i]);
    
}

回复列表 (共2个回复)

沙发

你试试改成结构体,而非数组来存储牌的类型呢。

板凳


好的  谢谢指点

我来回复

您尚未登录,请登录后再回复。点此登录或注册