C++实现洗牌算法!

#include
#include

using namespace std;
void shuffle(int [][13]);//======洗牌======
void deal(const int [][13],const char *[],const char *[]);//=======一次发完牌======

int main()
{
const char *suit[4]={"红桃","黑桃","梅子","方块"};
const char *face[13]={"A","2","3","4","5",
"6","7","8","9","10",
"J","Q","K"};
int deck[4][13]={0};

shuffle(deck);

cout<<"/n=====================================================/n";
deal(deck,face,suit);

cout<<"/n=====================================================/n";
system("PAUSE");
return 0;

}
void shuffle(int wDeck[][13])
{
int row,col;
for(int card=1;card<=52;card++)
{
do
{
row=rand()%4;
col=rand()%13;

}while(wDeck[row][col]!=0);
wDeck[row][col]=card;
}

}
//======发牌========
void deal(const int wDeck[][13],const char *wFace[],const char *wSuit[])
{
for(int card=1;card<=52;card++)
for(int row=0;row<=3;row++)
for(int col=0;col<=12;col++)
{
if(wDeck[row][col]==card)
{
cout< < <<(card%2==0?"/n":"/t");
}
}
cout<<"***************************************************/n";
}

你可能感兴趣的:(C++实现洗牌算法!)