|
发表于 2009-12-21 19:44:00
|
显示全部楼层
Re:一个概率题,大家来算下……
#include <iostream>
using namespace std;
int he (int a,int b,int c,int d)
{
int x;
if(a>b)
x=b;
else
x=a;
if(x>c)
x=c;
else if(x>d)
x=d;
else
x=x;
x=a+b+c+d-x;
return x;
}
int main (void)
{
int a=18,c=0;
int b[4];
cout<<"请输入要统计的值"<<endl;
cin>>a;
for(b[0]=1,b[1]=1,b[2]=1,b[3]=0;b[0]+b[1]+b[2]+b[3]<24;)
{
if(b[3]<6)
{
b[3]=b[3]+1;
}
else if(b[2]<6)
{
b[2]=b[2]+1;
b[3]=1;
}
else if(b[1]<6)
{
b[1]=b[1]+1;
b[3]=1;
b[2]=1;
}
else
{
b[0]=b[0]+1;
b[3]=1;
b[2]=1;
b[1]=1;
}
if(a==he(b[0],b[1],b[2],b[3]))
{
cout<<b[0]<<b[1]<<b[2]<<b[3]<<endl;
c=c+1;
}
else
;
}
cout<<a<<"共出现"<<c<<"次"<<endl;
return 0;
}
|
|