Artificial Intelligence?
Time limit1sMemory limit128 MB
Given a word problem stating two of power, voltage, and current with optional metric prefixes, compute the missing quantity using P = U * I.
- Level
Easy3 of 10
- Topics
- String, Math, Implementation
- Solved
- No attempts yet
Problem
High school physics teachers often think that word problems are harder than pure calculations — after all, students first have to read and understand the problem.
So instead of stating a problem as "U=10V, I=5A, P=?", they phrase it like this: "You have an electrical circuit containing a battery with a voltage of U=10V and a light bulb. A current of I=5A flows through the bulb. What power is generated in the bulb?"
However, half of the students never pay attention to the text anyway. They simply pull the given values out of the text — U=10V, I=5A — and think: "Which formulas do I know? Ah yes, . Therefore . Done."
This does not always work, so these students are usually not the top scorers on physics tests — but the simple algorithm is generally good enough to pass the class.
Today we check whether a computer can pass a high school physics test. We focus on P-U-I problems: problems in which two of power, voltage, and current are given and the third is asked for.
Write a program that reads such a word problem and solves it using the simple algorithm above.
Input
The first line contains the number of test cases.
Each test case is a single line that contains exactly two data fields plus arbitrary extra words. A data field has the form I=xA, U=xV, or P=xW, where x is a real number. Directly before the unit (A, V, or W) one of the prefixes m (milli, ), k (kilo, ), or M (Mega, ) may appear. In summary, data fields follow this grammar:
DataField ::= Concept '=' RealNumber [Prefix] Unit
Concept ::= 'P' | 'U' | 'I'
Prefix ::= 'm' | 'k' | 'M'
Unit ::= 'W' | 'V' | 'A'
Additional guarantees:
- The equals sign ('=') never appears anywhere except inside a data field.
- There is no whitespace (tabs or spaces) inside a data field.
- Exactly one of the pairs (P and U), (P and I), or (U and I) is given.
Output
For each test case, print two lines:
- a line reading "Problem #k", where k is the test case number (starting from 1);
- a line giving the solution — voltage, power, or current, depending on which one was missing — written without any prefix and with exactly two decimal places.
Separate consecutive test cases with a blank line.