#include<iostream>
using namespace std;
#include<ctime>
#include<cmath>
#include<cstdlib>
#define ship 1
#define bar 2
#define water 3
int zuijiuzhe(void)
{
int x = -10;
int y = 0;
int step = 0;
//srand((unsigned)time(NULL));
while (abs(x) <= 10 && abs(y) <= 2)
{
switch (rand() % 10)
{
case 0:
y++;
break;
case 1:
y--;
case 2:
x--;
default:
x++;
}
step++;
}
if (x < -10)
{
cout << "走了" << step << "步后," << "回到酒馆继续喝酒" << endl;
return bar;
}
else
{
if (x > 10)
{
cout << "走了" << step << "步后," << "回到船上" << endl;
return ship;
}
else
{
cout << "走了" << step << "步后," << "掉进水中" << endl;
return water;
}
}
}
int main()
{
int shipman = 0;
int barman = 0;
int waterman = 0;
int brunk = 0;
cout << "请输入醉酒者总人数:";
cin >> brunk;
for (int i = 0; i < brunk; i++)
{
switch (zuijiuzhe())
{
case ship:
shipman++;
break;
case bar:
barman++;
break;
case water:
waterman++;
break;
}
}
cout << "************************************************" << endl;
cout << "醉酒者总人数为:" << brunk << "人" << endl ;
cout << "其中回到船上的人总共有:" << shipman << "人" << endl;
cout << "其中回到酒吧继续喝酒的人总共有:" << barman << "人" << endl;
cout << "其中掉入水中的人总共有:" << waterman << "人" << endl;
return 0;
}