#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){
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
printf("%c%d",6,(card[i]-78+4)/2);break;
case 11:
printf("%cJ",6);break;
case 12:
printf("%cQ",6);break;
case 13:
printf("%cK",6);break;
case 14:
printf("%cA",6);break;
}
case 4:
if(card[i]==104||card[i]==105)
printf("joker");
if(card[i]==106||card[i]==107)
printf("JOKER");
break;
default:
break;
}
}
}
main()
{
int i,j,flag,n; \*remain数组用来放底牌*\
int remain[9],cards1[26],cards2[26],cards3[26],cards4[26]; \*cards数组用来放发的牌,每人25张用大小为26的数组是为了方便排序*\
int whole[100]; \*whole数组用来放出过的牌,方便电脑记忆*\
srand((unsigned)time(NULL));
for(i=0;i<25;i++)
{
cards1[i]=rand()%108;
flag=i;
for(j=0;j<i;j++)
{
if(!(cards1[j]-cards1[i]))
{
i--;
break;
}
}
if(i!=flag)
continue;
}
for(i=0;i<25;i++)
{
cards2[i]=rand()%108;
flag=i;
for(n=0;n<25;n++)
{
if(!(cards1[n]-cards2[i]))
{
i--;
break;
}
}
if(i!=flag)
continue;
for(j=0;j<i;j++)
{
if(!(cards2[j]-cards2[i]))
{
i--;
break;
}
}
if(i!=flag)
continue;
}
for(i=0;i<25;i++)
{
cards3[i]=rand()%108;
flag=i;
for(n=0;n<25;n++)
{
if(!(cards1[n]-cards3[i])||!(cards2[n]-cards3[i]))
{
i--;
break;
}
}
if(i!=flag)
continue;
for(j=0;j<i;j++)
{
if(!(cards3[j]-cards3[i]))
{
i--;
break;
}
}
if(i!=flag)
continue;
}
for(i=0;i<25;i++)
{
cards4[i]=rand()%108;
flag=i;
for(n=0;n<25;n++)
{
if(!(cards1[n]-cards4[i])||!(cards2[n]-cards4[i])||!(cards3[n]-cards4[i]))
{
i--;
break;
}
}
if(i!=flag)
continue;
for(j=0;j<i;j++)
{
if(!(cards4[j]-cards4[i]))
{
i--;
break;
}
}
if(i!=flag)
continue;
}
for(j=0,i=0;j<25&&i<100;j++){
whole[i]=cards1[j];
i++;
whole[i]=cards2[j];
i++;
whole[i]=cards3[j];
i++;
whole[i]=cards4[j];
i++;
}
insertsort(whole,101);
for(n=0,i=0;n<8;n++,i++){
for(j=0;j<100;j++){
if(i==whole[j])
i++;
}
remain[n]=i;
}
insertsort(cards1,26);
insertsort(cards2,26);
insertsort(cards3,26);
insertsort(cards4,26);
insertsort(remain,9);
printf("\nCards of four players are:\n\n");
printf("East player:\n ");
output(cards1,26);printf("\n");
printf("South player:\n ");
output(cards2,26);printf("\n");
printf("West player:\n ");
output(cards3,26);printf("\n");
printf("North player:\n ");
output(cards4,26);printf("\n\n");
printf("The left cards are:\n\n");
printf(" ");
output(remain,9);printf("\n");
getch();
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |