编程介的小学生 2017-09-10 13:47 采纳率: 20.5%
浏览 713
已采纳

AutoFish

You've built an amazing fish-catching robot, but you've discovered one small flaw: the robot can't decide whether to fish or cut bait.
You've designed a language for the Control of Oceangoing Devices (COD) which you plan to use to program the robot. COD has three instructions:

fish Fish for ten minutes.
bait Cut bait for ten minutes.
lunch No operation for ten minutes.

Bait is required to catch fish. The robot must cut bait for twenty minutes (execute two bait instructions) to generate a single bait unit, enough bait to catch a single fish. Other instructions (fish and lunch) may be interleaved between the two bait instructions that generate a bait unit. The robot has storage for three bait units; it cannot cut any more bait if it is already storing three bait units. If the robot is storing three bait units, a bait instruction is treated as if it were a lunch instruction (a NOP). Catching a fish consumes a bait unit.

Fish have deterministic behaviour. A fish cannot be caught more often than once every seventy minutes, and after a fish has been caught the robot must fish for thirty minutes before catching another fish (they get shy). In order to successfully complete a fish instruction, the robot must have a least one bait unit. If the robot has no bait, a fish instruction cannot be successfully completed and is treated as if it were a lunch instruction. When the robot first starts fishing, a fish is caught on the first fish instruction that completes (beginner's luck). If at least one fish has already been caught then a fish is caught on the completion of a fish instruction if and only if: 1) the fish instruction is at least the seventh COD instruction executed since the last instruction on which a fish was caught, and 2) the fish instruction is at least the third fish instruction successfully completed since the last instruction on which a fish was caught.

The execution of a lunch instruction allows time to pass, but has no other purpose.

The robot starts with no bait; no fish have been caught.

Input

Input consists of a sequence of fish, bait and lunch instructions, terminated by a blank line.

Output

Output for each case is a line containing a single integer, indicating the number of fish the robot has caught at the end of the sequence.

Sample Input

fish
fish
lunch
bait
fish
bait
fish
bait
bait
fish
fish
fish
fish
lunch
lunch
lunch
lunch
fish
fish
fish

Sample Output

2

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-27 14:11
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形