斗地主发牌

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main()
{
    char colors[6]={'S','H','D','C','K','X'};
    char cards[13]={'A','2','3','4','5','6','7','8','9','T','J','Q','K'};
    char user1[17][13]={0};
    char user2[17][13]={0};
    char user3[17][13]={0};
    char othercards[3][13]={0};
    char arrcards[54][10]={0};
    int count=0;
    while(count<54){
        char card[3]={0};
        int colorindex=rand()%6;
        card[0]=colors[colorindex];
        int numberindex=-1; 
        if((*(colors+colorindex))!='K'&&(*(colors+colorindex))!='X'){
            numberindex=rand()%13;
            card[1]=cards[numberindex];
        }
        int isRepeat = 0;
        for(int i = 0;i<count;i++){
            if(strcmp(card,arrcards[i])==0){
                isRepeat=1;
                break;
            }
        }
        if(isRepeat==0){
            strcpy(arrcards[count],card);
            count++;
        }
    }
    putchar('\n');
    int j=0;
    while(j<17){
        int k=rand()%54;
        char tool[3]={0};
        tool[0]=arrcards[k][0];
               tool[1]=arrcards[k][1];
         int isRepeat = 0;
                for(int i = 0;i<j;i++){
                        if(strcmp(tool,user1[j])==0){
                                isRepeat=1;
                                break;
                        }
                }
                if(isRepeat==0){
                        strcpy(user1[j],tool);
                        j++;
                }

    }
    printf("user1: ");
    for(int i=0;i<17;i++){
                printf("%-3s",user1[i]);
    }
    putchar('\n');
         j=0;
        while(j<17){
                int k=rand()%54;
                char tool1[3]={0};
                tool1[0]=arrcards[k][0];
                tool1[1]=arrcards[k][1];
                 int isRepeat = 0;
                for(int i = 0;i<j;i++){
                        if(strcmp(tool1,user2[j])==0 || strcmp(user1[i],user2[j])==0){
                                isRepeat=1;
                                break;
                        }
                }
                if(isRepeat==0){
                        strcpy(user2[j],tool1);
                        j++;
                }
        }
    printf("user2: ");
        for(int i=0;i<17;i++){
                printf("%-3s",user2[i]);
        }
        putchar('\n');
     j=0;
        while(j<17){
                int k=rand()%54;
                char tool2[3]={0};
                tool2[0]=arrcards[k][0];
                tool2[1]=arrcards[k][1];
                 int isRepeat = 0;
                for(int i = 0;i<j;i++){
                        if(strcmp(tool2,user3[j])==0 || strcmp(user2[i],user3[j])==0 ||strcmp(user1[i],user3[j])==0){
                                isRepeat=1;
                                break;
                        }
                }
                if(isRepeat==0){
                        strcpy(user3[j],tool2);
                        j++;
                }

        }
    printf("user3: ");
        for(int i=0;i<17;i++){
                printf("%-3s",user3[i]);
        }
        putchar('\n');
    j=0;
        while(j<3){
                int k=rand()%54;
                char tool3[3]={0};
                tool3[0]=arrcards[k][0];
                tool3[1]=arrcards[k][1];
                 int isRepeat = 0;
                for(int i = 0;i<j;i++){
                        if(strcmp(tool3,othercards[j])==0 || strcmp(user2[i],othercards[j])==0 ||strcmp(user1[i],othercards[j])==0 ||strcmp(user3[i],othercards[j])==0){
                                isRepeat=1;
                                break;
                        }
                }
                if(isRepeat==0){
                        strcpy(othercards[j],tool3);
                        j++;
                }

        }
    printf("othercard: ");
        for(int i=0;i<3;i++){
                printf("%-3s",othercards[i]);
        }
        putchar('\n');

    return 0;
}

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值