#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;
}
斗地主发牌
最新推荐文章于 2024-08-28 21:25:50 发布