#C5803. Resistor Network Calculation
Resistor Network Calculation
Resistor Network Calculation
You are given a series of resistors and the type of their connection. Your task is to compute the equivalent resistance of the network.
If the resistors are connected in series, the equivalent resistance is the sum of the resistances:
\[ R_{eq} = \sum_{i=1}^{n} R_i \]If they are connected in parallel, the equivalent resistance is given by:
\[ R_{eq} = \frac{1}{\sum_{i=1}^{n} \frac{1}{R_i}} \]For the parallel case, the result should be rounded to three decimal places.
Read the input from standard input (stdin) and output the result to standard output (stdout).
inputFormat
The input consists of three lines:
- An integer n — the number of resistors.
- n space-separated numbers representing the values of the resistors.
- A string that is either "series" or "parallel" indicating the connection type.
outputFormat
Output the equivalent resistance. For series connection, output the sum. For parallel connection, output the result rounded to three decimal places.## sample
3
2 3 4
series
9