const string RANKS[] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
const string SUITS[] = {"Spades", "Hearts", "Diamonds", "Clubs"};
和
void showHand(vector<int> &deck) {
cout << endl;
for (int i = 0; i < 4; i++) {
cout << "Player " << i + 1 << ": ";
for (int k = 0; k < 13; k++) {
cout << card[k][i] << " ";
}
cout << endl;
}
}
在这种情况下,这仅打印卡片的整数值,但不打印相应的套装和等级。我该如何显示它们?
答案 0 :(得分:0)
首先,你需要将卡片索引转换为两个等级并适合indizes,如两个函数
int suit_index(int card_index){
return card_index / 13;
}
int rank_index(int card_index){
return card_index % 13;
}
鉴于此,最内层循环内的打印当前是&#34; cout&lt;&lt;卡[k] [i]&lt;&lt; &#34; &#34 ;;&#34;变
card = card[k][i];
suit = suit_index(card);
rank = rank_index(card);
cout << RANKS[rank] << " of " << SUITS[suit] << " ";
(或者您直接使用suit = card / 13;等等,如果您的转换不同,只想拥有占位符)