Vector Calculator
Vector Calculator
Listen up soldier! You are going into the front lines, maggot! I don't wanna hear about "integers" or "real numbers anymore". Drop and give me twenty, and then implement a calculator that can calculate 2d vector operations!!!!!!.
Input format
The first line has one integer, n, the number of queries.
n lines follow, each with a query.
There are 3 query types with vector outputs.
Add queries are in format "ADD ax ay bx by". The answer to this query is the sum of vectors (ax,ay) and (bx,by)
Multiplication queries are in format "MULT ax ay b". The answer to this query is the multiplication of vector (ax,ay) and the scalar b
Rotation queries are in format "ROT ax ay ang". The answer to this query is the resulting vector after rotating vector (ax,ay) around the origin by ang degrees counterclockwise
There are 3 queries with scalar outputs.
Triangle queries are in format "TRI ax ay bx by cx cy". The answer to this query is area of the triangle with points (ax,ay), (bx,by) and (cx,cy)
Dot product queries are in format "DOT ax ay bx by". The answer to this query is the dot product of vectors (ax,ay) and (bx,by)
Cross product queries are in format "CROSS ax ay bx by". The answer to this query is the cross product of vectors (ax,ay) and (bx,by)
1<n<1e5
All numbers in queries are in range [−1e5,1e5]
Output format
For each query, output the answer on a separate line. For vector outputs, print out the answer in format "x y", where x is the horizontal component, and y is the vertical component For scalar outputs, simply print out the answer in a separate line.
Tip: be careful of the print format, we don't the program to print in scientific form, or to be skimping out on decimal places. For c++ users, cout<<setPrecision(10), imported from the iomanip library can resolve this.
Answers within 1e-5 of the reference answer will be accepted.
Examples
3
ADD 3.5 4.5 6 -3
ROT 1 4.5 90
MULT -3892 3 0.5
9.5 1.5
-4.5 1
-1946 1.5
2
TRI 0 0 1 0 0 1
DOT 3000 4000 4000 -3000
0.5
0
1
CROSS -3.5 -6.5 7 13
0
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.