|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||256 MB||6||2||2||33.333%|
Wouldn't it be cool if your favorite language had feature XYZ? Well, your professor has started you on your journey to design your own language with your own features. Perhaps you'll even find time to include blackjack, among other things, in the language. Until then, your first class assignment is to write an interpreter for a simple programming language.
The language has a single data type, a 32-bit signed integer.
Operators and statements that generally operate on booleans (
0 (zero) as false and all other values as true.
Operators that generally result in a boolean (
0 (zero) for false and
1 (one) for true.
Each variable name is a single lowercase letter between 'a' and 'z'. All variables are implicitly initialized to
0 (zero) at the beginning of each program.
Each simple statement (
end while) is on its own line.
There are no blank lines.
Any amount of whitespace (space or tab) may occur before or after any token (operator, variable name, keyword, constant, etc.). It will not occur within a token. It is only guaranteed to be present between 2 alphanumeric tokens.
A statement consists of any of the following:
if expression statements else statements end if
Run the zero or more statements in the first block if
expression evaluates to true (non-zero). Otherwise, run the zero or more statements in the second block.
if expression statements end if
Run the zero or more statements in the block if
expression evaluates to true (non-zero). Otherwise, skip the block.
while expression statements end while
expression. If it is true (non-zero), run the zero or more statements in the block and return to the start of the
while statement to re-evaluate the expression. Otherwise, skip the block.
set name = expression
Set the variable named name to the result of
Write the result of
expression to stdout on its own line.
An expression consists of a variable name, integer value (sequence of digits with a value between 0 and 231-1 inclusive), or any of the operations listed below.
Some operators have a higher precedence than others;
1+2*3 is equivalent to
1*2+3 is equivalent to
Within a single precedence level, binary operators group left-to-right, and unary operators group right-to-left. For example,
1+2-3 is equivalent to
!-x is equivalent to
||unary minus (additive inverse)|
||logical negation (not)|
||less than or equal|
||greater than or equal|
All final and intermediate values will fit in a 32-bit signed integer; no overflow detection is necessary.
%) by 0 will not occur.
Input consists of 1 or more programs. Each begins with a line containing the number of lines (N, 1 <= N <= 50) in that program. The following N lines contain the program to run. No line is longer than 100 characters. Input is terminated when N equals 0 (zero).
Output consists only of the result of the
11 set n = 22 set s = 1 while n > 1 if n % 2 == 0 set n = n / 2 else set n = 3 * n + 1 end if set s = s + 1 end while print s 1 print ((2*4-6/3)*(3*5+8/4))-(2+3)+1/2*0 0