其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
以前用C++写的洗牌和发牌的程序

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

int pk[]={501,502,
          101,102,103,104,105,106,107,108,109,110,111,112,113,
    201,202,203,204,205,206,207,208,209,210,211,212,213,
    301,302,303,304,305,306,307,308,309,310,311,312,313,
    401,402,403,404,405,406,407,408,409,410,411,412,413};
int a[14],b[14],c[13],d[13];

class pack
{
public:
 void makepack();
 void fapack();
 void disp();
};

void pack::makepack()
{
 int temp,r,times;
 cout<<"\n 洗牌次数:";
 cin>>times;
 cout<<endl;

 for(int j=0;j<=times;j++)
 {
  for(int i=0;i<53;i++)
  {
   r=int(float(53-i)*rand()/RAND_MAX)+1;
   temp=pk[i];
   pk[i]=pk[r];
   pk[r]=temp;
  }
 }
}

void pack::fapack()
{
 int i,j;
 j=0;
 cout<<"正在发牌..."<<endl;
 for(i=0;i<=53;i++)
 {
  a[j]=pk[i];
  i++;
        b[j]=pk[i];
  i++;
  if(j<=12)
  {
   c[j]=pk[i];
   i++;
   d[j]=pk[i];
  }
  if(j>12)
   i++;
  j++;
 }
}

void pack::disp()

 cout<<"a的牌是:";
 for(int i=0;i<14;i++)
  cout<<a[i]<<",";
 cout<<endl;

 cout<<"b的牌是:";
 for(i=0;i<14;i++)
  cout<<b[i]<<",";
 cout<<endl;

 cout<<"c的牌是:";
 for(i=0;i<13;i++)
  cout<<c[i]<<",";
 cout<<endl;

 cout<<"d的牌是:";
 for(i=0;i<13;i++)
  cout<<d[i]<<",";
 cout<<endl;
}

int main()
{
 cout<<"==============模拟洗牌&&发牌==============="<<endl;
 cout<<"=说明:                                           ="<<endl;
 cout<<"=    以5开头的为鬼                        ="<<endl;
 cout<<"=    以1开头的为红桃                      ="<<endl;
 cout<<"=    以2开头的为方块                      ="<<endl;
 cout<<"=    以3开头的为葵扇                      ="<<endl;
 cout<<"=    以4开头的为草花                      ="<<endl;
 cout<<"==========================================="<<endl;

 pack mypack;
 mypack.makepack();
 mypack.fapack();
 
 cout<<endl;

 mypack.disp();

 getchar();
 return 0;
}




相关文章

相关软件