1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
void shuffle(int[][2]);
int main()
{
int j,deck[52][2];
string suit[4]={"hearts","diamonds","spades","clubs"};
string card[13]={"Ace","Deuce","Three","Four","Five","Six",
"Seven","Eight","Nine","Ten","Jack","Queen","King"};
srand(time(0));
shuffle(deck);
cout<<"deck-after shuffled:\n";
for(j=0;j<52;j++)
cout<<card[deck[j][1]]<<" of "<<suit[deck[j][0]]<<endl;
cout<<endl;
system("pause");
return 0;
}
void shuffle(int deck[][2])
{bool cards[4][13];
int i,j,num,type;
for(i=0;i<4;i++)
for(j=0;j<13;j++)
cards[i][j]=false;
for(j=0;j<52;j++)
{do
{
num=rand();
type=rand()%4;
}while(cards[type][num]);
deck[j][0]=type;
deck[j][1]=num;
cards[type][num]=true;
}
return;
}
|