#K75052. Replace Failing Grades
Replace Failing Grades
Replace Failing Grades
You are given a list of student grades. A grade is considered failing if it is less than 40. Your task is to replace every failing grade with the average of all passing grades (grades which are at least 40). The average should be calculated as follows:
\(\text{average} = \text{round}\Big(\frac{\sum_{g \ge 40} g}{\#(g \ge 40)}\Big)\)
If there are no passing grades, replace every grade with 0.
Note: The result should be printed as a single line of space-separated integers after processing the list.
inputFormat
The input begins with an integer (n) (1 ≤ n ≤ 1000) on the first line, representing the number of grades. The second line contains (n) space-separated integers representing the grades.
outputFormat
Output a single line containing the modified list of grades in the same order, with failing grades replaced by the average of the passing grades (rounded to the nearest integer). If there are no passing grades, failing grades should be replaced by 0.## sample
5
35 42 37 29 50
46 42 46 46 50