|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shuffle(int array[], int length); //洗牌
void deal(int array[], int player[3][14]); //发牌
void show(char names[3][20], int player[3][14]); //显示
void shuffle(int array[], int length)
{
int i, index, temp,
srand(time(NULL));
for (i = 0; i < length; i++)
{
index = rand() % (length - i) + i;
if (index != i)
{
temp = array[i];
array[i] = array[index];
array[index] = temp;
}
}
}
void deal(int array[], int player[3][14])
{
int i, j, k = 0;
for (i = 0; i < 14; i++)
{
for (j = 0; j < 3; j++)
{
player[j][i] = array[k++];
}
}
}
void show(char names[3][20], int player[3][14])
{
int i, j, poke;
for (i = 0; i < 3; i++)
{
printf("%s的牌是: \n", names[i]);
for (j = 0; j < 14; j++)
{
poke = player[i][j];
if (poke < 11 && poke > 0)
{
printf("方%d ", poke);
}
else if (poke < 21 && poke > 10)
{
printf("梅%d ", poke - 10);
}
else if (poke < 31 && poke > 21)
{
printf("红%d ", poke - 20);
}
else if (poke < 41 && poke > 30)
{
printf("黑%d ", poke - 30);
}
else
{
switch (poke)
{
case 41: printf("方j "); break;
case 42: printf("方Q "); break;
case 43: printf("方K "); break;
case 44: printf("梅J "); break;
case 45: printf("梅Q "); break;
case 46: printf("梅K "); break;
case 47: printf("红J "); break;
case 48: printf("红Q "); break;
case 49: printf("红K "); break;
case 50: printf("黑J "); break;
case 51: printf("黑Q "); break;
case 52: printf("黑K "); break;
case 53: printf("小王 "); break;
case 54: printf("大王 "); break;
}
}
}
}
}
int main(void)
{
int i, array[54];
int player[3][14];
char names[3][20];
char ch;
for (i = 0; i < 54; i++) //扑克牌初始
{
array[i] = i + 1;
}
for (i = 0; i < 3; i++)
{
printf("请输入第%d号玩家名字: ", i + 1);
scanf("%s", names[i]);
}
do
{
shuffle(array, 54);
deal(array, player);
show(names, player);
do
{
printf("重新洗牌(Y/N): ");
ch = gechar();
}while (ch != 'Y' && ch != 'N');
}while(ch == 'Y');
return 0;
}
抄代码的时候就请认真一点呀
问题全在这 3 张图片上,看图片的时候要非常认真
左边是你抄的代码
|
-
|