#C14659. Employee Salary Analysis
Employee Salary Analysis
Employee Salary Analysis
You are given data for a company’s employees. Each employee record has four fields: Name
, Age
, Department
, and Salary
. Some salaries may be missing and are indicated by the string NA
.
Your task is to perform two steps:
- Replace each missing salary with the overall average salary computed from the available (non-missing) salary entries. The overall average is computed over all employees with a provided salary.
- Compute the average salary for each department. In this problem, the departments of interest are
HR
,Engineering
, andFinance
.
The averages must be output in the order: HR, Engineering, Finance. Each average should be printed on a new line and rounded to exactly 2 decimals.
Note: It is guaranteed that the input will include at least one record for each of the three departments.
inputFormat
The input is read from stdin
and has the following format:
- The first line contains an integer
N
representing the number of employees. - The next
N
lines each contain the details of one employee in the following order, separated by spaces:
Name Age Department Salary
Here, Salary
is a number if available, or the string NA
if the salary is missing.
outputFormat
The output is written to stdout
and should consist of exactly three lines.
- The first line is the average salary of the HR department.
- The second line is the average salary of the Engineering department.
- The third line is the average salary of the Finance department.
Each average must be rounded to 2 decimals.
## sample10
Alice 25 HR 50000
Bob 30 Engineering 60000
Charlie 45 Engineering 80000
David 35 HR 45000
Eva 28 Finance 52000
Frank 40 Engineering NA
Grace 50 Finance 65000
Hannah 23 HR 47000
Ian 33 Engineering 72000
Jack 41 Finance NA
47333.33
67718.75
58625.00
</p>