#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
using namespace std;
void shuffle(int [][13]);
void deal(const int[][13],const char*[],const char *[],int [][2]);
void pairs(const int[][13],const int [][2],const char*[]);
void threeofkind(const int[][13],const int [][2],const char *[]);
void fourofkind(const int [][13],const int[][2],const char*[]);
void flushhand(const int[][13],const int [][2],const char*[]);
void straighthand(const int [][13],const int [][2],const char*[],const char*[]);
int mian()
{
const char *suit[]={"hearts","diamonds","clubs","spades"};
const char *face[]={"ace","deuce","three","four","five","six",
"seven","eight","nine","ten","jack","queen","king"};
int deck[4][13]={0};
int hand[5][2]={0};
srand(time(0));
shuffle(deck);
deal(deck,face,suit,hand);
pairs(deck,hand,face);
threeofkind(deck,hand,face);
fourofkind(deck,hand,face);
flushhand(deck,hand,suit);
straighthand(deck,hand,suit,face);
return 0;
}
void shuffle(int wdeck[][13])
{
int row;
int column;
for(int card=1;card<=52;card++){
do{
row=rand()%4;
column=rand()%13;
}while(wdeck[row][column]!=0);
wdeck[row][column]=card;
}
}
void deal(const int wdeck[][13],const char *wface[],
const char *wsuit[],int whand[][2])
{
int r=0;
cout<<"the hand is :\n";
for(int card=1;card<6;card++)
for(int row=0;row<=3;row++)
for(int column=0;column<=12;column++)
if(wdeck[row][column]==card){//这里是取已经洗好了的前5张牌
whand[r][0]=row;
whand[r][1]=column;
cout<<setw(5)<<wface[column]
<<" of"<<setw(8)<<left
<<wsuit[row]<<(card%2==0?'\n':'\t')
<<left;
r++;
}
cout<<'\n';
}
void pairs(const int wdeck[][13],const int whand[][2],const char *wface[])
{
int counter[13]={0};
for(int r=0;r<5;r++)
++counter[whand[r][1]];
cout<<'\n';
for(int p=0;p<13;p++)
if(counter[p]==2)
cout<<"the hand contains a pair of"<<wface[p]<<"'s.\n";
}
void threeofkind(const int wdeck[13],const int whand[][2],const char*wface[])
{
int counter[13]={0};
for(int r=0;r<5;r++)
++counter[whand[r][1]];
cout<<'\n';
for(int p=0;p<13;p++)
if(counter[p]==3)
cout<<"the hand contains three"<<wface[p]<<"'s.\n";
}
void fourofkind(const int wdeck[][13],const int whand[][2],const char*wface[])
{
int counter[13]={0};
for(int r=0;r<5;r++)
++counter[whand[r][1]];
cout<<'\n';
for(int p=0;p<13;p++)
if(counter[p]==4)
cout<<"the hand contains four"<<wface[p]<<"'s.\n";
}
void flushhand(const int wdeck[][13],const int whand[][2],const char*wsuit[])
{
int counter[13]={0};
for(int r=0;r<5;r++)
++counter[wsuit[r][0]];
cout<<'\n';
for(int p=0;p<13;p++)
if(counter[p]==5)
cout<<"the hand contains a flush of"<<wsuit[p]<<"'s.\n";
}
void strainghthand(const int wdeck[][13],const int whand[][2],const char *wsuit[],
const char *wface[])
{
int s[5]={0};
int temp;
for(int r=0;r<5;r++)
s[r]=whand[r][1];
for(int pass=0;pass<4;pass++)
for(int comp=pass+1;comp<5;comp++)
if(s[pass]>s[comp]){
temp=s[pass];
s[pass]=s[comp];
s[comp]=temp;
}
if(s[4]-1==s[3] && s[3]-1==s[2] && s[2]-1==s[1] && s[1]-1==s[0]){
cout<<"the hand contains a strainght consisting of\n";
for(int j=0;j<5;j++)
cout<<wface[whand[j][1]]<<" of"<<wsuit[whand[j][0]]
<<'\n';
}
}