#include <iostream>
#include <iomanip>
using namespace std;
#include <string>
#include <fstream>
#include <cstdlib>
#include <ctime>
//#include "drunkman.h"
class drunkman
{
public:
void walk(int,int);
};
void drunkman::walk(int x,int y)
{
int step;
srand(time(0));
for(int i=0;i<1000;i++)
{
step=rand()%4;
switch(step)
{
case 0:
x++;
break;
case 1:
y++;
break;
case 2:
y--;
break;
case 3:
x--;
break;
}
}
cout<<"the man is at "<<"("<<x<<" , "<<y<<")"<<endl;
}
int main()
{
drunkman w;
int x,y;
cout<<"the man is at (x,y)"<<endl;
cin>>x>>y;
w.walk(x,y);
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.59