作者sb0917 (QQ)
看板NTUBIME101HW
標題[C++] 考前不負責猜題-發牌程式
時間Tue Nov 18 12:03:42 2008
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
void shuffle(int []);
int main()
{
srand(time(NULL));
int poker[52];
char sign;
for(int i=0;i<52;i++)
poker[i] = i+1;//把牌排好
shuffle(poker);
cout << "player1\tplayer2\tplayer3\tplayer4\n"
<< "-------\t-------\t-------\t-------\n";
for(int i=0;i<52;i++)//輸出牌
{
sign = poker[i]%4 + 3;//請看ASCii的3~6號
cout << setw(2) << sign << setw(3) << poker[i]%13+1 << "\t";
if((i+1)%4==0)
cout << endl;
}
system("pause");
return 0;
}
void shuffle(int poker_in[])//洗牌函式
{
int change1,change2,temp;
for(int i=0;i<10000;i++)
{
change1 = rand()%52;
change2 = rand()%52;
temp = poker_in[change2];
poker_in[change2] = poker_in[change1];
poker_in[change1] = temp; //亂數交換牌換一萬次總該乾淨了吧
}
}
看看就好...
因為這程式用的東西都在考試範圍裡ˊˋ
想說陣列和函式的應用(8-3)老師堅持會考...
這隻程式難度比樂透低 應該不難了解@@
祝大家考試順利!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.59
推 ck940560:計中卷王! 快推 11/18 14:33
→ ck940560:原來有現成的花色符號...看到標題我還以為要用中文敘述.. 11/18 14:34