{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003e\u003ci\u003eLittle Quilt\u003c/i\u003e is a small language introduced by Ravi Sethi in his book ‘Programming Languages’.\u003c/p\u003e\r\n\r\n\u003cp\u003eHere, a restricted version of Little Quilt is presented. The language is defined by the following BNF grammar:\u003c/p\u003e\r\n\r\n\u003cpre\u003e \u0026lt; QUILT \u0026gt; ::\u003d A | B | turn(\u0026lt; QUILT \u0026gt;) | sew(\u0026lt; QUILT \u0026gt;,\u0026lt; QUILT \u0026gt;)\u003c/pre\u003e\r\n\r\n\r\n\u003cp\u003eA 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.\u003c/p\u003e\r\n\r\n\u003cp\u003eThe instruction \u003ctt\u003eturn(x)\u003c/tt\u003e turns the quilt x 90 degrees clockwise. The following table illustrates the primitive quilts as well as examples of the effect of the \u003ctt\u003eturn()\u003c/tt\u003e operation:\u003c/p\u003e\r\n\r\n\u003cp\u003e\u003c/p\u003e\u003ccenter\u003e\u003cimg src\u003d\"CDN_BASE_URL/fa9ffbd869deaa93aa50dc9d22149b37?v\u003d1715804387\" alt\u003d\"Quilt Operations\" border\u003d\"0\"\u003e\u003c/center\u003e\u003cp\u003e\u003c/p\u003e\r\n\r\n\u003cp\u003eAccordingly, the instruction \u003ctt\u003esew(x,y)\u003c/tt\u003e 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 \u003ctt\u003esew(A,turn(B))\u003c/tt\u003e:\u003c/p\u003e\r\n\r\n\u003cp\u003e\u003c/p\u003e\u003ccenter\u003e\u003cimg src\u003d\"CDN_BASE_URL/2e6834a71a9b4f04025ea12199df820b?v\u003d1715804387\" alt\u003d\"Quilt\" border\u003d\"0\"\u003e\u003c/center\u003e\u003cp\u003e\u003c/p\u003e\r\n\r\n\u003cp\u003ewhile the \u003ctt\u003esew(turn(sew(B,turn(B))),A)\u003c/tt\u003e generates an error message.\u003c/p\u003e\r\n\r\n\u003cp\u003eYour job is to build an interpreter of the Little Quilt language.\u003c/p\u003e\r\n\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eThe 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.\u003c/p\u003e\r\n\r\n\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003eThe output file contains the quilts produced as a result of interpreting the input expressions.\u003c/p\u003e\r\n\r\n\u003cp\u003eEach quilt must be preceded by a line, left aligned, with the format\u003c/p\u003e\r\n\r\n\u003cp\u003e\u003ctt\u003eQuilt i:\u003c/tt\u003e\u003cbr\u003e\r\nwhere i is the quilt number, starting at 1. If the expression interpretation generates and error, the word \u003ctt\u003eerror\u003c/tt\u003e must be printed.\u003c/p\u003e\r\n\r\n\u003ch3\u003eExample\u003c/h3\u003e\r\n\r\n\u003cdiv\u003e\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003esew(turn(sew(B,turn(B))),\r\nturn(sew(turn(B),B))) ;\r\n\n\n\r\nsew(turn(sew(B,turn(B))),A);\r\nsew(turn(sew(A,turn(A))),\r\nturn(turn(\r\n\n\r\nturn(sew(A,turn(A))))))\r\n;\r\n\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eQuilt 1:\r\n||--\r\n||--\r\n--||\r\n--||\r\nQuilt 2:\r\nerror\r\nQuilt 3:\r\n\\\\//\r\n+\\/+\r\n+/\\+\r\n//\\\\\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\r\n\n\u003c/div\u003e"}}]}