Frankenstein and the Flasks
Time limit1sMemory limit1024 MB
Given the classes of two reagents (N, Z, Q, R) and an operation (+, -, *), find the smallest class that contains every possible result.
- Level
Easy2 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
Doctor Frankenstein decided to take up the most interesting pursuit on Earth: mixing flasks of reagents.
Each reagent is described by one real number, its coefficient. The coefficient determines the class of the reagent. There are four classes:
- : the coefficient is a natural number, that is, a number that arises naturally when counting (for example, , , , , and so on).
- : the coefficient is an integer. Integers include the natural numbers, their negatives, and (for example, , , ).
- : the coefficient is a rational number, that is, a number that can be written as a fraction , where and are integers (for example, , , ).
- : the coefficient is a real number. Real numbers include both rational and irrational numbers (for example, , ).
Each class contains the previous one, so every reagent is assigned the smallest class that contains it.
Two reagents can be mixed. The mixing produces one of three reactions: addition, subtraction, or multiplication. The new reagent has a coefficient equal to the sum, the difference, or the product of the two coefficients, respectively.
Frankenstein took two reagents and mixed them. Given the reaction and the classes of the two reagents, determine the class of the resulting reagent. Determine the class in the general case. For example, is a special case, but in general the product of two real numbers is real, and not necessarily even rational.
Input
A single line contains three characters. The second character is +, -, or *. The other two are each one of N, Z, Q, or R.
The first character is the class of the first reagent, the second is the reaction (+ for addition, - for subtraction, * for multiplication), and the third is the class of the second reagent.
Output
Print a single character, N, Z, Q, or R: the class of the resulting reagent.