uva 10134 - AutoFish(simulation)
2014-02-28 23:02
375 查看
Question 4: AutoFish
The Problem
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. |
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.Input consists of a sequence of fish, bait and lunch instructions, terminated by the end-of-file.Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.Output is a line containing a single integer, indicating the number of fish the robot has caught at the end of the sequence.Sample Input
1 fish fish lunch bait fish bait fish bait bait fish fish fish fish lunch lunch lunch lunch fish fish fish
Sample Output
2
#include <iostream>#include <cstdio>using namespace std;int bait , fish , remain , sum;string execute;void initial(){bait = 0;fish = 0;remain = 0;sum = 0;}void readcase(){while(getline(cin , execute) && execute.length() != 0){if(execute == "fish"){if(bait >= 2 && ((remain >= 7 && fish >= 2) || sum == 0)){sum++;fish = 0;remain = 0;bait -= 2;}else{fish++;}remain++;}if(execute == "bait"){if(bait < 6) bait++;remain++;}if(execute == "lunch") remain++;}printf("%d\n" , sum);}int main(){int t;scanf("%d" , &t);getchar();getline(cin , execute);while(t--){initial();readcase();if(t) printf("\n");}return 0;}[/code]
相关文章推荐
- Paste Deployment简介以及cinder-api-paste.ini的解析(1)
- Checkstyle手册
- Java知识总结-常见流
- Java知识总结-常见流
- ADB server didn't ACK问题解决
- HDU 1754 I Hate It (线段树)
- 英雄会15题 阶乘与整除
- python修改文件内容
- HDU - 1723 - Distribute Message
- 基于按annotation的hibernate主键生成策略
- Nodejs初阶之express
- 12235 - Help Bubu(状态压缩dp)
- ZOJ-2416
- Android Touch事件分发机制
- EBS Form开发 弹性域定义中的参数<->
- Websocket协议之握手连接
- javascript对象之Array
- ZOJ 2864 Catch the thief
- Effective Java 06 Eliminate obsolete object references
- MVC数据验证使用小结