📄 1.cpp
字号:
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
using namespace std;
void deal(const int[][13], const char*[], const char*[],const char*[]);
void shuffle(int[][13]);
void main()
{
const char *suit[4] = { "Hearts", "Clubs", "Diamonds", "Spades"};
const char *face[13] = { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
const char *color[2] = { "[ Red ]", "[ Black ]"};
int deck[4][13] = { 0 };
shuffle (deck);
deal(deck, face, suit, color);
}
void deal (const int wDeck[][13], const char* wface[], const char* wsuit[], const char*wcolor[])
{
int c;
int color_r[13] = { 0 };
int color_b[13] = { 0 };
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<<right<<setw(5)<<wface[col]<<" of "<<setw(8)<<left<<wsuit[row];
srand(time(0));
while(1)
{
c = rand() % 2;
if (c == 0 && color_r[col] < 2)
break;
else if (c == 1 && color_b[col] < 2)
break;
}
if(c == 0)
{
color_r[col]++;
cout<<setw(10)<<left<<wcolor[0];
}
else if (c == 1)
{
color_b[col]++;
cout<<setw(10)<<left<<wcolor[1];
}
if(col >= 10 && col <= 12)
cout<<'*';
cout<<(card % 2 == 0 ? '\n' : '\t');
}
}
void shuffle(int wDeck[][13])
{
int row;
int col;
srand ( time(0) );
for (int card = 1; card <= 52; card++)
{
do
{
row = rand() % 4;
col = rand() % 13;
}while( wDeck[row][col] != 0 );
wDeck[row][col] = card;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -