Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01._Company_Roster
- {
- public class Employees
- {
- public Dictionary<string, double> Names { get; set; }
- public double TotalSalary { get; set; }
- public int Counter { get; set; }
- public double AverageSalary { get; set; }
- }
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- Dictionary<string, Employees> employees = new Dictionary<string, Employees>();
- for (int i = 0; i < n; i++)
- {
- var input = Console.ReadLine().Split();
- var name = input[0];
- var salary = double.Parse(input[1]);
- var department = input[2];
- if (!employees.ContainsKey(department))
- {
- var employee = new Employees();
- employee.Counter = 1;
- employee.Names = new Dictionary<string, double>();
- employee.Names.Add(name, salary);
- employee.TotalSalary += salary;
- employee.AverageSalary = employee.TotalSalary / employee.Counter;
- employees[department] = employee;
- }
- else
- {
- employees[department].Names.Add(name, salary);
- employees[department].Counter ++;
- employees[department].TotalSalary += salary;
- employees[department].AverageSalary = employees[department].TotalSalary / employees[department].Counter;
- }
- }
- employees = employees.OrderByDescending(x => x.Value.AverageSalary).ToDictionary(x => x.Key, y => y.Value);
- foreach (var department in employees)
- {
- Console.WriteLine($"Highest Average Salary: {department.Key}");
- foreach (var name in department.Value.Names.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"{name.Key} {name.Value:F2}");
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement