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

建议使用的浏览器:

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

3201:Little Quilt

题目描述

Little Quilt is a small language introduced by Ravi Sethi in his book ‘Programming Languages’. Here, a restricted version of Little Quilt is presented.

The language is defined by the following BNF grammar:

<QUILT> ::= A | B | turn(<QUILT>) | sew(<QUILT>,<QUILT>)

A and B represent the two primitive quilts. Each primitive quilt corresponds to a matricial arrangement of 2 × 2 characters. turn() and sew() are operations over quilts.

The instruction turn(x) turns the quilt x 90 degrees clockwise. The following table illustrates the primitive quilts as well as examples of the effect of the turn() operation:

A//
/+
turn(A)\\
+\
turn(turn(A))+/
//
turn(turn(turn(A)))\+
\\
B--
--
turn(B)||
||

Accordingly, the instruction sew(x,y) sews quilt x to the left of quilt y. Both x and y must have the same height, otherwise an error will be generated. The following figure represents the result of sew(A,turn(B)):

//||
/+||

while the sew(turn(sew(B,turn(B))),A) generates an error message.

Your job is to build an interpreter of the Little Quilt language.

输入解释

The input file will be a text file containing different Little Quilt expressions, each one ended by a semicolon character (;). Space and new line characters must be ignored; this means that an expression may span several lines.

输出解释

The output file contains the quilts produced as a result of interpreting the input expressions.

Each quilt must be preceded by a line, left aligned, with the format

Quilt i:

where i is the quilt number, starting at 1. If the expression interpretation generates and error, the word

error

must be printed.

输入样例
sew(turn(sew(B,turn(B))),
       turn(sew(turn(B),B)))   ;


   sew(turn(sew(B,turn(B))),A);
sew(turn(sew(A,turn(A))),
 turn(turn(

   turn(sew(A,turn(A))))))

   ;
输出样例
Quilt 1:
||--
||--
--||
--||
Quilt 2:
error
Quilt 3:
\\//
+\/+
+/\+
//\\

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

题目来源 Colombia 2006

源链接: POJ-3201

最后修改于 2020-10-29T06:55:43+00:00 由爬虫自动更新

共提交 0

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