[推荐]发牌(能运行,但最后提示有错误内存不能为写)
#include<iostream>#include<ctime>
#include<cstdlib>
using namespace std;
void print(int);
const int s=51;
void main()
{
int a[s+1];
int i,j;
for(i=0;i<=s;i++)
a[i]=i;
int hand [4][5];
srand(time(0));
int temp;
for(i=s;i>=31;i--)
{
int r=rand()%(i+1);
temp=a[r];
a[r]=a[i+1];
a[i+1]=temp;
}
int ss=s;
for(i=0;i<=4;i++)
for(j=0;j<=3;j++)
{
hand[j][i]=a[ss];
ss--;
}
for(i=0;i<=3;i++)
{
cout<<"Player"<<(i+1)<<"'s hand:"<<endl;
for(j=0;j<=4;j++)
{
print(hand[j][i]);
cout<<" ";
cout<<endl;
}
}
}
void print(int card_value)
{
if(card_value%4==0)
cout<<"黑桃";
else if(card_value%4==1)
cout<<"梅花";
else if(card_value%4==2)
cout<<"方片";
else
cout<<"红桃";
if(card_value<=36)
cout<<(card_value/4+2);
else if(card_value<=39)
cout<<"J";
else if(card_value<=43)
cout<<"Q";
else if(card_value<=47)
cout<<"K";
else
cout<<"A";
}