SHARE
TWEET

CompanyRoster

a guest Aug 18th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Company_Rosted
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             // READ INPUT
  12.  
  13.             int numberOfEmployees = int.Parse(Console.ReadLine());
  14.  
  15.             List<Employee> listOfEmployees = new List<Employee>();
  16.  
  17.             for (int i = 0; i < numberOfEmployees; i++)
  18.             {
  19.                 string[] input = Console.ReadLine().Split();
  20.  
  21.                 string name = input[0];
  22.                 double salary = double.Parse(input[1]);
  23.                 string dep = input[2];
  24.  
  25.                 var newEmployee = new Employee(name, salary, dep);
  26.  
  27.                 listOfEmployees.Add(newEmployee);
  28.             }
  29.  
  30.             //CALCULATE THE HIGHEST AVERAGE SALARY
  31.  
  32.             listOfEmployees = listOfEmployees.OrderBy(x => x.Department).ToList();
  33.  
  34.             var departments = new Dictionary<string, List<double>>();
  35.                  
  36.  
  37.             for (int i = 0; i < listOfEmployees.Count; i++)
  38.             {
  39.                 string newDepartment = listOfEmployees[i].Department;
  40.                 double newSlary = listOfEmployees[i].Salary;
  41.                 if (!departments.ContainsKey(newDepartment))
  42.                 {
  43.                     departments[newDepartment] = new List<double>();
  44.                 }
  45.                 departments[newDepartment].Add(newSlary);
  46.             }
  47.             string departmentMaxAverage = departments.OrderByDescending(x => x.Value.Average()).First().Key;
  48.  
  49.             //PRINT OUTPUT
  50.  
  51.             listOfEmployees = listOfEmployees
  52.                 .Where(x => x.Department == departmentMaxAverage)
  53.                 .OrderByDescending(x => x.Salary)
  54.                 .ToList();
  55.  
  56.             Console.WriteLine($"Highest Average Salary: {departmentMaxAverage}");
  57.  
  58.             foreach (var men in listOfEmployees)
  59.             {
  60.                 Console.WriteLine($"{men.Name} {men.Salary:f2}");
  61.             }
  62.         }
  63.     }
  64.  
  65.     class Employee
  66.     {
  67.         public string Name { get; set; }
  68.         public double Salary { get; set; }
  69.         public string Department { get; set; }
  70.  
  71.         public Employee(string name, double salary, string department)
  72.         {
  73.             this.Name = name;
  74.             this.Salary = salary;
  75.             this.Department = department;
  76.         }
  77.     }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top