Chariots of fire

Telecommunication engineering is tough. Every year, students learn how to apply the rules of equivalent resistance:

Your professor here at UPC went nuts and now wants you to apply this set of rules to a very complicated circuit of resistors. However, he swears that you can resolve it with just these two formulas. He is even going to tell you which resistors are connected in parallel and which in series! In the old times it wasn’t like that! Well …

Input

Input consists of several cases. Every case is a (perhaps huge) string describing a circuit. An ‘S’ begins a series setting, and a ‘P’ begins a parallel setting. Between parentheses there is a comma-separated list with two or more descriptions for the subcircuits. An ‘R’, together with a strictly positive real number between parentheses, describes each resistor. There are no spaces.

Output

For every circuit, its equivalent resistance with three digits after the decimal point. The cases have no precision issues.

Problem information

Author: Ricardo Martín

Generation: 2026-01-25T11:14:58.845Z

© Jutge.org, 2006–2026.
https://jutge.org