#include <stdio.h>
#include <stdlib.h>
void main(void)
{
int i,j;
char ch1,ch2;
char s[104];/* 存放一副牌 */
char a[]="hdsc";/* 定义花色 */
/* 定义牌值 */
char b[14] = "akqj1098765432";
/* 生成一副新牌 */
for(i=0;i<4;i++)
{
for(j=0;j<13;j++)
{
s[2*j+26*i] = a[i];
s[2*j+26*i+1] = b[j];
}
}
randomize(); /* 初始化随机数发生器 */
for(i=0;i<52;i++)
{
j = random(52-i);
ch1 = s[2*j]; /* 与最后一张牌交换花色 */
s[2*j] = s[102-2*i];
s[102-2*i] = ch1;
ch2 = s[2*j+1]; /* 与最后一张牌交换牌值 */
s[2*j+1] = s[103-2*i];
s[103-2*i] = ch2;
}
printf("nn");
for(i=0,j=0;i<104;i+=2,j++) /* 显示大乱后新牌 */
{
if(!(j%13))
{
printf("nnn"); /* 13张牌为一组 */
}
printf(" %c%c",s[i],s[i+1]);
}
getch();
}
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <iostream>
// using namespace std;
int main()
{
const char *c = "0123456789abcdefghijklmnopqrstuvwxyz";
srand(static_cast<unsigned int>(time(null)));
std::cout << "the random char array is:";
for(int i = 0; i < 5; ++i)
{
std::cout << std::endl;
int index = 0 ;
for(int j = 0; j < 5; ++j)
{
index = rand() % strlen(c);
std::cout << c[index ]
<< c[index]
<< " ";
}
}
std::cout << std::endl;
return 0;
}