看板 C_and_CPP 關於我們 聯絡資訊
有些部份改了一下 可以判斷順子跟同花順 ------------------------------------- #ifdef kkk int card; /* card counter */ int row; /* row counter */ int column; /* column counter */ zzz tmp[5]; int c=0; /* 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 ) { if (wSuit[ row ]=="Hearts")tmp[c].type=2,tmp[c++].num=atoi(wFace[ column ]); if (wSuit[ row ]=="Diamonds")tmp[c].type=3,tmp[c++].num=atoi(wFace[ column ]); if (wSuit[ row ]== "Clubs")tmp[c].type=4,tmp[c++].num=atoi(wFace[ column ]); if (wSuit[ row ]== "Spades")tmp[c].type=1,tmp[c++].num=atoi(wFace[ column ]); } /* end if */ } /* end for */ } /* end for */ } /* end for */ straight_flush(tmp); system("PAUSE"); } /* end function deal */ #endif #ifndef kkk #define kkk #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.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 ] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" }; /* 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 */ struct zzz{ int type; int num; }; void straight_flush(zzz * yyy){ int i,j,t,f=1; zzz tmp[5]; memcpy(tmp,yyy,5*sizeof(zzz)); for (i=0;i<5;i++){ printf("num:%d type:%d\n",tmp[i].num,tmp[i].type); } printf("\n"); for(i=0;i<4;i++){ for(j=0;j<4;j++){ if(tmp[j].num>tmp[j+1].num){ t=tmp[j].num; tmp[j].num=tmp[j+1].num; tmp[j+1].num=t; } } } for(i=0;i<4;i++) if(tmp[i].type!=tmp[i+1].type){ f=0; break; } if(tmp[0].num+4==tmp[4].num&&f) printf("It's straight flush\n"); else if(tmp[0].num+4==tmp[4].num) printf("It's straight\n"); else printf("It's not straight\n"); } /* deal cards in deck */ void deal( const int wDeck[][ 13 ], const char *wFace[], const char *wSuit[] ) { #include __FILE__ #endif -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.134.226.149 ※ 編輯: loveflames 來自: 140.134.226.149 (05/21 00:40)