#C12902. Average Student Scores by Category
Average Student Scores by Category
Average Student Scores by Category
You are given data representing the scores of students in various categories. Each category is provided in one line along with a list of scores. Some scores may be missing and are represented by the string NA
. Your task is to calculate the average score for each category and output the result. If a category has no valid scores (i.e., all scores are NA
), then output NA
as the average for that category.
The average should be computed as the sum of valid scores divided by the number of valid scores and displayed with one decimal place. The output should be in the same order as the input.
Note: Even though the problem is inspired by data analysis and plotting tasks, you only need to calculate and output the averages in a competitive programming style using standard input and output.
inputFormat
The first line contains an integer n
, the number of categories. Each of the following n
lines represents one category and is formatted as follows:
CategoryName k score1 score2 ... scorek
Here, CategoryName
is a string (without spaces), k
is an integer representing the number of scores, and each score
is either an integer (or float) or the string NA
which indicates a missing score.
outputFormat
For each category, print a single line containing the category name and the calculated average separated by a space. The average should be displayed with one decimal place if there is at least one valid score; otherwise, print NA
if there are no valid scores.
For example:
Math 70.0 Science 84.8## sample
1
Math 5 80 90 70 60 50
Math 70.0
</p>