作者jason06184 (講座)
看板C_and_CPP
標題[問題] 撲克牌牌組判斷
時間Thu May 20 21:09:05 2010
遇到的問題:
我不知該怎樣下筆 = A =
希望得到的正確結果:
我想要判斷是pair.twopair.鐵枝.葫蘆.順子.同花順
程式跑出來的錯誤結果:
沒有結果要怎樣跑出錯誤勒....
開發平台:
Dev-C++
補充說明:
是要從這裡改
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* prototypes */
void shuffle( int wDeck[][ 13 ] );
void deal( const int wDeck[][ 13 ], const char *wFace[], const char *wSuit[]
);
int main( void )
{
/* initialize suit array */
const char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" };
/* initialize face array */
const char *face[ 13 ] =
{ "ACE", "2", "3", "4",
"5", "6", "7", "8",
"9", "10", "Jack", "Queen", "King" };
/* initialize deck array */
int deck[ 4 ][ 13 ] = { 0 };
srand( time( 0 ) ); /* seed random-number generator */
shuffle( deck );
deal( deck, face, suit );
return 0; /* indicates successful termination */
} /* end main */
/* shuffle cards in deck */
void shuffle( int wDeck[][ 13 ] )
{
int row; /* row number */
int column; /* column number */
int card; /* counter */
/* for each of the 52 cards, choose slot of deck randomly */
for ( card = 1; card <= 5; card++ ) {
/* choose new random location until unoccupied slot found */
do {
row = rand() % 4;
column = rand() % 13;
} while( wDeck[ row ][ column ] != 0 ); /* end do...while */
/* place card number in chosen slot of deck */
wDeck[ row ][ column ] = card;
} /* end for */
} /* end function shuffle */
/* deal cards in deck */
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int card; /* card counter */
int row; /* row counter */
int column; /* column counter */
/* deal each of the 52 cards */
for ( card = 1; card <= 5; card++ ) {
/* loop through rows of wDeck */
for ( row = 0; row <= 3; row++ ) {
/* loop through columns of wDeck for current row */
for ( column = 0; column <= 12; column++ ) {
/* if slot contains current card, display card */
if ( wDeck[ row ][ column ] == card ) {
printf( "%5s of %-8s%c", wFace[ column ], wSuit[ row ],
card % 2 == 0 ? '\n' : '\t' );
} /* end if */
} /* end for */
} /* end for */
} /* end for */
system("PAUSE");
} /* end function deal */
簡單來說我跑出來要是像這樣的東西
4 of Hearts
7 of Diamonds
4 of Diamonds
7 of Clubs
7 of Spades
這副牌為7葫蘆
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 134.208.43.62
※ 編輯: jason06184 來自: 134.208.43.62 (05/20 21:10)
→ Dannvix:這份 code 好眼熟... 05/20 21:17
推 BSpowerx:我怎麼好像不久前才看過類似的問題= =? 05/20 21:18
→ jason06184:這份 CODE 是從某本書抄下來的 05/20 21:22
→ Dannvix:難怪,是螞蟻書吧 XD 05/20 21:25
→ jason06184:YES 05/20 21:26
推 benson2826:想知道+1 05/20 21:28
→ yoco315:這沒救了 明年再修 05/20 21:58
推 VictorTom:Deja vu....XD 05/20 22:08
→ Dannvix:是說 Victor 前輩提到的「Deja Vu」好有趣!長知識 XD 05/20 23:31
推 VictorTom:XD 小弟只是來亂入的 XD 05/21 00:00
→ suhenry:朱同學...我好像是助教唷~作業應該自己做呀!!! 05/21 10:38
推 milkdragon:助教是對的!!!! 05/21 10:39
推 chonader:助教萬歲!!! 05/21 10:39
推 ilovethis:助教是對的!助教萬歲! 05/21 10:41
推 ksmrt0123:Deja vu 是系統被入侵的表徵 (The matrix, 無誤) 05/21 11:37
→ jason06184:有時PO版問人比直接抄襲同學還慘..... 05/21 12:34
推 siuol:助教啊~可憐可憐原PO吧XD 他晚了兩秒鐘交 XDDDDDDDDDDDDDDD 05/22 13:09