#K76767. Calculate RGB Lightness
Calculate RGB Lightness
Calculate RGB Lightness
You are given a series of RGB values provided as input. Each line of the input contains three integers r, g, and b (where 0 \le r, g, b \le 255
) separated by spaces. The input terminates with a line containing only end
.
Your task is to calculate the lightness for each RGB set using the formula:
\[
L = \frac{\max(r, g, b) + \min(r, g, b)}{2}
\]
where \max(r, g, b)
is the maximum of the three values and \min(r, g, b)
is the minimum of the three values. The result is computed using integer division. For each dataset (line), print the calculated lightness on a new line to standard output.
inputFormat
The input consists of multiple lines. Each non-terminal line contains three space-separated integers representing the RGB values (r, g, b). The input ends with a line containing "end". Read the input from standard input (stdin).
outputFormat
For each RGB dataset provided in the input (except the terminating line), output the computed lightness on a separate line to standard output (stdout).## sample
255 0 0
0 255 0
0 0 255
220 220 220
128 128 128
0 0 0
255 255 255
end
127
127
127
220
128
0
255
</p>