Advertisement
Again_89

01. Company Roster

Feb 5th, 2019
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01._Company_Roster
  6. {
  7. public class Employees
  8. {
  9. public Dictionary<string, double> Names { get; set; }
  10. public double TotalSalary { get; set; }
  11. public int Counter { get; set; }
  12. public double AverageSalary { get; set; }
  13. }
  14.  
  15. class Program
  16. {
  17. static void Main()
  18. {
  19. int n = int.Parse(Console.ReadLine());
  20.  
  21. Dictionary<string, Employees> employees = new Dictionary<string, Employees>();
  22. for (int i = 0; i < n; i++)
  23. {
  24. var input = Console.ReadLine().Split();
  25. var name = input[0];
  26. var salary = double.Parse(input[1]);
  27. var department = input[2];
  28.  
  29. if (!employees.ContainsKey(department))
  30. {
  31. var employee = new Employees();
  32. employee.Counter = 1;
  33. employee.Names = new Dictionary<string, double>();
  34. employee.Names.Add(name, salary);
  35.  
  36. employee.TotalSalary += salary;
  37. employee.AverageSalary = employee.TotalSalary / employee.Counter;
  38.  
  39. employees[department] = employee;
  40. }
  41. else
  42. {
  43. employees[department].Names.Add(name, salary);
  44. employees[department].Counter ++;
  45. employees[department].TotalSalary += salary;
  46. employees[department].AverageSalary = employees[department].TotalSalary / employees[department].Counter;
  47. }
  48. }
  49.  
  50. employees = employees.OrderByDescending(x => x.Value.AverageSalary).ToDictionary(x => x.Key, y => y.Value);
  51.  
  52. foreach (var department in employees)
  53. {
  54. Console.WriteLine($"Highest Average Salary: {department.Key}");
  55. foreach (var name in department.Value.Names.OrderByDescending(x => x.Value))
  56. {
  57. Console.WriteLine($"{name.Key} {name.Value:F2}");
  58. }
  59. break;
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement