#include #include #include int main(){ int i,j,c1,c2; int tmp; int card[52];//設定一副牌 char color[] = {'S','H','D','C'};//花色 char number[] = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};//號碼 int player[4]; /*洗牌*/ for(i=0;i<52;i++){ card[i]=i; } srand(time(NULL)); for(i=0;i<1000;i++){ c1 = rand()%52; c2 = rand()%52; tmp = card[c1]; card[c1] = card[c2]; card[c2] = tmp; } /*發牌*/ for(i=0;i<4;i++){//初始化,一開始各player手上牌的總和為零 player[i] = 0; } for(j=0;j<2;j++){//算總和 for(i=0;i<4;i++){ player[i] = player[i]+(card[i+(j*(j+3))]%13+1); } } for(i=0;i<4;i++){//印出結果 printf("player %d\n",i+1);//player從一開始 printf("sum is %d ",player[i]); for(j=0;j<2;j++){ // 花色為點數/13, 點數為取13餘數(1~12)+1 printf("%c%c ",color[card[i+(j*(j+3))] / 13],number[card[i+(j*(j+3))] % 13]); } printf("\n"); } }