推 typenephew:不難懂 11/15 22:24
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x=0,y=0,step;
cout << "醉漢一開始在: (" << x << "," << y << ")\n";
for(int i=0;i<1000;i++)
{
step = rand()%4;
switch(step)
{
case 0:
x--;
break;
case 1:
y++;
break;
case 2:
x++;
break;
case 3:
y--;
break;
}
}
cout << "醉漢走了一千步後在: (" << x << "," << y << ")\n";
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.232.106.25