52張撲克牌,隨機洗牌,然后發(fā)牌,并把每個玩家的牌按從大到小的順序顯示
創(chuàng)新互聯(lián)公司專注于武川企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站制作。武川網(wǎng)站建設(shè)公司,為武川等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站策劃,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)大小規(guī)則:AKQJ1098765432
輸出效果:
完整代碼:?
#include#include#includeusing namespace std;
//卡牌結(jié)構(gòu)體
typedef struct deck
{
int row = -1; //花色
int column = -1; //面值
}deck;
//遍歷deck數(shù)組看是否已經(jīng)用過某張牌,若用過返回真
bool judge(deck wDeck[], int row_, int column_, int n)
{
for (int i = 0; i< n; i++)
{
if (wDeck[i].row == row_ && wDeck[i].column == column_)
return true;
}
return false;
}
//洗牌
void shuffle(deck wDeck[])
{
int row_;
int column_;
for (int card = 0; card< 52; card++)
{
do
{
row_ = rand() % 4;
column_ = rand() % 13;
} while (judge(wDeck, row_, column_, card));
wDeck[card].row = row_;
wDeck[card].column = column_;
}
}
//將牌按從大到小排序
void selectSort(deck wDeck[])
{
int i, j, index;
deck temp;
for (i = 0; i< 52; i++)
{
index = i;
for (j = index + 4; j< 52; j += 4)
{
if (wDeck[j].column >wDeck[index].column)
index = j;
}
if (index != i)
{
temp = wDeck[i];
wDeck[i] = wDeck[index];
wDeck[index] = temp;
}
}
}
//發(fā)牌
void deal(deck wDeck[], const char* wFace[], const char* wSuit[])
{
//排序,讓每個玩家的牌按從大到小的順序顯示
selectSort(wDeck);
//打印
cout<< setw(12)<< "Player1"<< setw(24)<< "Player2"
<< setw(24)<< "Player3"<< setw(25)<< "Player4\n";
for (int i = 0; i< 52; i++)
{
cout<< setw(6)<
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧