📄 twodwalk.cpp
字号:
#include <iostream>
using namespace std;
#include "prompt.h"
#include "walk2d.h"
// simulate two random walkers at once
// Owen Astrachan, 6/29/96, modified 5/1/99
int main()
{
int numSteps = PromptRange("enter # steps",0,30000);
RandomWalk2D frog(numSteps,1); // define two random walkers
RandomWalk2D toad(numSteps,1);
int samePadCount = 0; // # times at same location
frog.Init(); // initialize both walks
toad.Init();
while (frog.HasMore() && toad.HasMore())
{ // if (frog.Current() == toad.Current())
if (frog.Current().distanceFrom(toad.Current()) < 1.0)
{ samePadCount++;
}
frog.Next();
toad.Next();
}
cout << "frog position = " << frog.Position() << endl;
cout << "toad position = " << toad.Position() << endl;
cout << "# times at same location = " << samePadCount << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -