Babbling Brooks

A series of streams run down the side of a mountain. The mountainside is very rocky so
the streams split and rejoin many times. At the foot of the mountain, several streams
emerge as rivers. Your job is to compute how much water flows in each river.
At any given elevation there are n streams, labelled 1 to n from left-to-right. As we
proceed down the mountainside, one of the streams may split into a left fork and a right
fork, increasing the total number of streams by 1, or two streams may rejoin, reducing the
total number of streams by 1. After a split or a rejoining occurs, the streams are
renumbered consecutively from left-to-right. There is always at least one stream and
there are never more than 100 streams.
The first line of input contains n, the initial number of streams at some high altitude. The
next n lines give the flow in each of the streams from left-to-right. Proceeding down the
mountainside, several split or rejoin locations are encountered. For each split location,
there will be three lines of input;
a line containing 99 (to indicate a split)
a line containing the number of the stream that is split
a line containing a number between 0 and 100, the percentage of flow from the split
stream that flows to the left fork. (The rest flows to the right fork).
For each join location, there will be two lines of input;
a line containing 88 (to indicate a join)
a line containing the number of the stream that is rejoined with the stream to its right
The flow from both joined streams is combined. After the last split or join location will
be:
a single line containing 77 (to indicate end of input)
Your job is to determine how many streams emerge at the foot of the mountain and what
the flow is in each. Your output is a sequence of real numbers, rounded to the nearest
integer, giving the flow in rivers 1 through n.
Sample Input (Input file : brooks.in)
3
10
20
30
99
1
50
88
3
88
2
77
Output for Sample Input (Output file : brooks.out)
5 55
can you help me with this one...i don't understand it.

Certainly! I can help you understand the problem and guide you on how to solve it.

The problem is asking us to compute the amount of water flowing in each river at the foot of the mountain, given a series of streams that split and rejoin multiple times.

To solve this problem, we need to follow these steps:

1. Read the initial number of streams, `n`, from the first line of input.
2. Read the flow in each stream from the next `n` lines, from left to right.
3. Initialize an array or list to store the flow in each stream.
4. Iterate through the split and join locations until the end of input (indicated by the line containing 77).
- For a split location (indicated by the line containing 99):
- Read the number of the stream that is split and the percentage of flow that goes to the left fork.
- Calculate the flow in the left fork stream by multiplying the current flow of the split stream by the percentage and dividing by 100.
- Calculate the flow in the right fork stream by subtracting the flow in the left fork stream from the current flow of the split stream.
- Insert the flow of the left fork stream at the corresponding position in the array or list.
- Insert the flow of the right fork stream at the position right after the left fork stream in the array or list.
- Adjust the values of `n` (number of streams) and update the array or list accordingly.
- For a join location (indicated by the line containing 88):
- Read the number of the stream that is rejoined with the stream to its right.
- Calculate the combined flow of the rejoined streams by summing their individual flow values.
- Remove the flow value of the stream that is rejoined with the right stream from the array or list.
- Adjust the values of `n` (number of streams) and update the array or list accordingly.
5. Print the number of streams (`n`) and the rounded flow values of each river.

Following these steps, we can compute how many streams emerge at the foot of the mountain and what the flow is in each river.

Let me know if you have any specific questions or need further assistance with implementing the solution.