frogwalk.cpp
来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 29 行
CPP
29 行
#include <iostream>using namespace std;#include "dice.h"#include "prompt.h"// simulate one-dimensional random walk// Owen Astrachan, 8/13/94, modified 5/1/99int main(){ int numSteps = PromptRange("enter # of steps",0,20000); int position = 0; // "frog" starts at position 0 Dice die(2); // used for "coin flipping" int k; for(k=0; k < numSteps; k++) { switch (die.Roll()) { case 1: position++; // step to the right break; case 2: position--; // step to the left break; } } cout << "final position = " << position << endl; return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?