-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathConsoleApplication1.cpp
63 lines (59 loc) · 1.18 KB
/
ConsoleApplication1.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* @author : wen-pinn fang <[email protected]>
* @version : 1.0
*/
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int card[52];
int player[2][13];
char suit[] = { 'C', 'D', 'H', 'S' };
char rank[13] = { 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K' };
srand(time(0));
int i;
//----- initial -----
for (i = 0; i < 52; i++)
card[i] = i;
//---- shuffle ------
int r1, r2;
for (i = 0; i < 104; i++)
{
r1 = rand() % 52;
r2 = rand() % 52;
int temp;
temp = card[r1];
card[r1] = card[r2];
card[r2] = temp;
}
//----show result of shuffle -----
for (i = 0; i < 52; i++)
{
cout << card[i] << "\t";
}
cout << endl;
cout << "--------------------------" << endl;
//---- send two hands
int j;
int k = 0;
for (i = 0; i < 13; i++)
for (j = 0; j < 2; j++)
{
player[j][i] = card[k];
k++;
}
//--- show table ----
for (i = 0; i < 2; i++)
{
for (j = 0; j < 13; j++)
{
cout << suit[player[i][j] / 13] << rank[player[i][j] % 13]<<" ";
}
cout << endl;
}
return 0;
}