A8305 | Logo Turtle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").
You are given a list of commands that will be given to the turtle. You have to change exactly $n$ commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list?
You are given a list of commands that will be given to the turtle. You have to change exactly $n$ commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list?
输入格式
The first line of input contains a string $commands$ — the original list of commands. The string $commands$ contains between 1 and 100 characters, inclusive, and contains only characters "T" and "F".
The second line contains an integer $n$ ( $1<=n<=50$ ) — the number of commands you have to change in the list.
The second line contains an integer $n$ ( $1<=n<=50$ ) — the number of commands you have to change in the list.
输出格式
Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list.
输入输出样例
输入 #1
FT 1
输出 #1
2
输入 #2
FFFTFFF 2
输出 #2
6
In the first example the best option is to change the second command ("T") to "F" — this way the turtle will cover a distance of 2 units.
In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one.
In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted