当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3972:BF

题目描述
BF is a language that was designed to challenge and amuse programmers. BF uses a simple machine model consisting, besides the program, of:

  • An array of 30,000 byte cells – byte value ranges from 0 to 255 - initialized to zeroes.

  • A movable pointer into a circular array (initialized to point to location 0)

  • Two streams of bytes for input and output (most often connected to a keyboard and a monitor respectively, and using the ASCII character encoding).


In this problem you are asked to implement a BF interpreter, your program should read a BF program and an input stream and should print the output stream.

BF syntax is easy, only the following commands are available:

CharacterSpelled asMeaning
>Greater thanIncrement the pointer (to point to the next cell to the right).
<Less thanDecrement the pointer (to point to the next cell to the left).
+Plus signIncrement (increase by one) the byte at the pointer.
-Minus signDecrement (decrease by one) the byte at the pointer.
.Dot (period)Puts the value of the byte at the pointer into the output stream.
,CommaAccept one byte of input - from the input stream - storing its value in the byte at the pointer.
[Left square bracketJump forward to the command after the corresponding ‘]’ if the byte at the pointer is zero.
]Right square bracketJump back to the command after the corresponding ‘[‘ if the byte at the pointer is nonzero.


The given BF programs will be syntactically valid also the ‘>’ and ‘<’ operators will never lead to a value outside range [0-30000].
输入解释
Input starts with the number of test cases on a line by itself. Then a number of test cases; each test case is formatted as follows.

  1. A BF program (possibly with extra letters and/or white space characters embedded anywhere in the text).

  2. A white space and a dollar sign – ‘$’ – indicating end of BF program.

  3. A space, the input stream, another space and a dollar sign terminator indicating the end of the input stream.

  4. A new line.


A test case may span on multiple lines and each two consecutive test cases are separated by a blank line.

The embedded text could be any characters except the dollar sign terminator, you should ONLY process the 8 commands and detect the end of program/input by the dollar signs, discard any other characters when processing. In the sample input only the relevant input is underlined, however in the real test cases there will be no signs of input termination except for the dollar signs.
输出解释
Output should be “Case “ then test case number (starting with 1) , a colon, a space followed by the contents of the BF program output stream and a new line after each test case.
输入样例
3
,>,>,>,.<.<.<. $ abcde $

This is a sample BF program ,>++++++[<-------->-],[<+>-]<. That
Prints the summation of 2 numbers $ 23 $

,>,> ++++[<++++++++>-]<. >++++[<<++++++++>>-]<<. Adds to
every cell 8*4=32 and prints 'em in reverse order $ AB $
输出样例
Case 1: dcba
Case 2: 5
Case 3: ba

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3972

最后修改于 2020-10-29T07:17:03+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 65536