C++爱好者 - 网友留言

1282阅读 0评论2008-12-17 3JTwF2T
分类:


由于你说的问题不大清楚,我大致按你的意思写了一下
小球的总数是随机分的1000一下的数。


#include
#include
#include
#include

#define BLACK 0
#define WHITE 1
#define WHITEBLACK 2

int WNum=0,BNum=0;

void main()
{  
srand((unsigned)time(NULL));
int M;
int NUM=(int)fabs(rand());
if(NUM>1000)
NUM=NUM%1000;
int MaxNum=NUM;
for(int i=0;i {

M=rand()%10;
if(M%2== WHITE)
WNum++;
         if(M%2==BLACK)
BNum++;
}
srand((unsigned)time(NULL));
int h=1;

while(NUM!=1)
{
cout<<"第"< int x1=rand()%10;
int x2=rand()%10;
if(x1%2==x2%2)
{   if(x1%2==WHITE)
    cout<<"本次取出两白球"< else
cout<<"本次取出两黑球"< WNum--;
}
if(x1%2!=x2%2)
{
cout<<"本次取出的球为一黑一白"< BNum--;
}
if(WNum==0)
{
WNum++;
MaxNum++;
}
    NUM--;
h++;
}
cout<<"**********************"< <<"共有"< if(WNum==1)
cout<<"最后的球为白球"< else
cout<<"最后的球为黑球"<
}


--------------------next---------------------

上一篇:C++爱好者 - 网友留言
下一篇:C++爱好者 - 网友留言