自己写的发牌代码,觉得还不错,来和大家分享
程序代码:
#include <stdio.h> main() { int i,x,y; //定义一副牌,由于没有10这个字符,所以在定义时用字符0代表10 char card[52][2]={{'3','A'},{'3','2'},{'3','3'},{'3','4'},{'3','5'},{'3','6'},{'3','7'},{'3','8'},{'3','9'},{'3','0'},{'3','J'},{'3','Q'},{'3','K'}, {'4','A'},{'4','2'},{'4','3'},{'4','4'},{'4','5'},{'4','6'},{'4','7'},{'4','8'},{'4','9'},{'4','0'},{'4','J'},{'4','Q'},{'4','K'}, {'5','A'},{'5','2'},{'5','3'},{'5','4'},{'5','5'},{'5','6'},{'5','7'},{'5','8'},{'5','9'},{'5','0'},{'5','J'},{'5','Q'},{'5','K'}, {'6','A'},{'6','2'},{'6','3'},{'6','4'},{'6','5'},{'6','6'},{'6','7'},{'6','8'},{'6','9'},{'6','0'},{'6','J'},{'6','Q'},{'6','K'}},temp[2]; for(i=0;i<100;i++) //洗牌 { x=rand()%52; y=rand()%52; temp[0]=card[x][0];card[x][0]=card[y][0];card[y][0]=temp[0]; temp[1]=card[x][1];card[x][1]=card[y][1];card[y][1]=temp[1]; } for(i=0;i<52;i++) //发牌 { if(card[i][1]=='0') //对10这张牌进行处理 printf("%3c%d ",(card[i][0]-48),10); else printf("%4c%c ",(card[i][0]-48),card[i][1]); if(i==12||i==25||i==38) printf("\n\n"); } printf("\n\n\n"); }