5.2将随机数模拟为不含大小王的扑克牌

/*模拟发不含大小王牌的扑克牌,
 将生成的随机数映射为每张扑克牌。
 按照花色(梅花、方块、红桃、黑桃)和大小(2~10、J、Q、K、A)顺序进行映射。
 映射规则如下:
 梅花:0-12
 方块:13-25
 红桃:26-38
 黑桃:39-51
 */
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
int i,sj;
int shu[52]={0};
srand((int)time(NULL));
for(i=1;i<=52;i++)
{
sj=rand()%52;
while(shu[sj]==1)
{
sj=rand()%52;
}
shu[sj]=1;
cout<<"第"<<i<<"张牌"<<endl;
switch(sj%4)
{
case 0:
cout<<"梅花";
break;
case 1:
cout<<"方块";
break;
case 2:
cout<<"红桃";
break;
case 3:
cout<<"黑桃";
break;
default:break;
}
switch(sj%13+1)
{
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
cout<<sj%13+1<<endl;
break;
case 1:
cout<<"A"<<endl;
break;
case 11:
cout<<"J"<<endl;
break;
case 12:
cout<<"Q"<<endl;
break;
case 13:
cout<<"K"<<endl;
break;
default:break;
}
}
return 0;
}

  

 

posted @ 2017-12-26 21:51  玄月卿  阅读(392)  评论(0编辑  收藏  举报