시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 0 | 0 | 0 | 0.000% |
Your task is to write a ‘desk calculator’ program that allows a user to evaluate expressions involving scalars and 3D vectors. Your calculator should accept assignment statements and expressions. For example, given input:
set x = 3 * (1, 2, 3+4) set y = (4, 5, 6) set z = x + y + (1, 1, 0) z
your calculator should save vectors (3, 6, 21)
and (4, 5, 6)
into variables x and y respectively. It should then do the two vector additions, and save (8, 12, 27)
into z
. The line with z
asks the program to display the current value of z
, which is (8, 12, 27).
a
.. z
).*
for scalar multiplication. (integer * vector or vector * integer or integer * integer)+
addition for either vectors or numbers-
subtraction for either vectors or numbers-
unary minus may be applied to vectors or scalars..
dot for the dot product between two vectors.X
upper case X
is for the cross product between two vectors.2 + - 3
is not allowed – it should be written as 2 – 3
{ } [ ]
and ( )
. Each can be used to control order of calculation (as in normal arithmetic) or to group expressions into a three vector. Normally each left parenthesis must be matched by a right parenthesis of the same style. However there is an exception to this rule, explained in the next paragraph.Parentheses are interpreted in the usual manner for arithmetic expressions, with one special exception. A right parenthesis closes all open expressions back to the nearest usage of a matching left parenthesis.
For example
( 2 + ( a + [ b + [ c + [ d + e ) )
is a valid expression equivalent to
( 2 + ( a + [ b + [ c + [ d + e ] ] ] ) )
because the first ) matches back to the ( before the ‘a’.
Input consists of a series of lines, each holding one statement (assignment or expression). Tokens of a statement may be preceded, separated or followed by zero or more spaces. Lines are no more than 500 characters long. End of input is indicated by a line holding the string ‘done’. You may assume that all input lines hold valid expressions.
Output consists of a series of results, one generated for each expression (not assignment) in the input. Results are displayed one per line. If the result is a scalar (integer) it is output with no surrounding spaces. If the result is a vector it is written as (integer,integer,integer) with no spaces.
set x = 3 * (1, 2, 3+4) set y = (4, 5, 6) set z = x + y + (1, 1, 0) z (1, 2, 2) - ((1, 1, -1).[(2,2,2) X (1,2,3], 4, 5) -1 - 2 done
(8,12,27) (-7,-2,-3) -3