作者agra (Samurai 7 超讚!!)
看板NTUEE108HW
標題Re: 龜兔賽跑...
時間Sat Dec 4 04:14:42 2004
※ 引述《jjjj222 (I'M windforce)》之銘言:
聽起來好像很好玩似的..
有沒有人能po個題目XD
5.17
(Simulation: The Tortoise and the Hare)
In the exercise, you will re-create the classic race of the tortoise
and the hare. You will use random number generation to develop a simulation
of this memorable event.
Our contenders begin the race at "square 1" of 70 squares. Each square
represents a possible position along the race course. The finish line is at
square 70. The first contender to reach or pass square 70 is rewarded with a
pail of fresh carrols and lettuce. The course weaves its way up the side of a
slippery mountain, so occasionally the contenders lose ground.
There is a clock that ticks once per second. With each tick of the
clock, your program should adjust the position of the animals according the
rules in Fig. 5.38.
==============================================================================
Percentage of
Animal Move type the time Actual move
==============================================================================
Tortiose Fast plod 50% 3 squares to the right
Slip 20% 6 squares to the left
Slow plod 30% 1 squares to the right
Hare Sleep 20% No move at all
Big hop 20% 9 squares to the right
Big slip 10% 12 squares to the left
Small hop 30% 1 squares to the right
Small slip 20% 2 squares to the left
------------------------------------------------------------------------------
Fig. 5.38 Rules for moving the tortoise and the hare.
Use variables to keep trackk of the position of the animals (i.e.,
position number are 1-70). Start each animal at position 1 (i.e., the "start-
ing gate"). If an animal slips left before square 1,move the animal back to
square 1.
Generate the percentage in the preceding table by producing a random
integer i in the range 1 <= i <= 10. For the tortoise, perform a "fast plod"
when 1 <= i <=5, a "slip" when 6 <= i <= 7 or a "slow plod" when 8 <= i <= 10.
Use a smiliar technique to move the hare.
Begin the race by printing
BANG !!!!!
AND THEY'RE OFF !!!!!
For each tick of the clock (i.e., each repetition of a loop), print a
70-position line showing the letter T in the tortoise's position and the
letter H in the hare's position. Ocassionally, the contevders land on the same
square. In this case, the tortoise bites the hare and your program should print
OUCH!!! beginning at that position. All print position other than the T,the H
or the OUCH!!! (in case of a tie) should blank.
After printing each line, test if either animal has reached or passed
square 70.If so, print the winner and terminate the simulation. If the tortoise
win, print TORTOISE WINS!!!YAY!!! If the hare wins, print Hare wins. Yuch. If
both animals win on the same clock tick, you may want to favor the turtle (
the "underdog"), or you may want to print It's a tie. If neither animal wins,
perform the loop again to simulate the next tick of clock. When you are ready
to run your program, assemble a group of fans to watch the race. You'll be
amazed how involved the audience gets!
--
呼..打完了(中間睡著三次orz)
想玩的人來玩玩看 真的很有趣!!
--
【Ι'M】 ▌ ▄▄
▄▄▄▌▄▄▄ ▄ ▄▄▃▂__
▌▌▌▄▄▄▄▌▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▌▌▌▄▌ ▌ ▄▌▌ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▌~>^.^<~喵!~~~
▄▄▄ Made by jjjj222
▄▄
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.249.186
推 davidtea:5.17題...很長耶......||| 61.228.88.36 12/04
→ davidtea:不過真的很有趣 XD 61.228.88.36 12/04
推 Aweather:推很有趣... 210.85.23.75 12/04
推 agra:真的很有趣... 140.112.239.237 12/04
→ agra:感受到爆發型選手和耐力型選手的差別 140.112.239.237 12/04
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.239.237
推 jjjj222:感謝^^" 140.112.249.186 12/04