SHARE
TWEET

Untitled

a guest Aug 17th, 2019 135 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, double>();
  35.  
  36.             int count = 1;
  37.  
  38.             string department = string.Empty;
  39.             double maxAvarage = double.MinValue;
  40.  
  41.             for (int i = 0; i < listOfEmployees.Count; i++)
  42.             {
  43.                 if (!departments.ContainsKey(listOfEmployees[i].Department))
  44.                 {
  45.                     string newDepartment = listOfEmployees[i].Department;
  46.                     double newSlary = listOfEmployees[i].Salary;
  47.  
  48.                     departments.Add(newDepartment, newSlary);
  49.                 }
  50.                 else
  51.                 {
  52.                     departments[listOfEmployees[i].Department] += listOfEmployees[i].Salary;
  53.                     count++;
  54.  
  55.                     if (listOfEmployees[i].Department != listOfEmployees[i+1].Department || i==listOfEmployees.Count-1)
  56.                     {
  57.                         departments[listOfEmployees[i].Department] /= count;
  58.  
  59.                         if (departments[listOfEmployees[i].Department]>maxAvarage)
  60.                         {
  61.                             maxAvarage = departments[listOfEmployees[i].Department];
  62.                             department = listOfEmployees[i].Department;
  63.                         }
  64.                         count = 1;
  65.                     }
  66.                 }
  67.             }
  68.  
  69.             //PRINT OUTPUT
  70.  
  71.             listOfEmployees = listOfEmployees
  72.                 .Where(x => x.Department == department)
  73.                 .OrderByDescending(x=>x.Salary)
  74.                 .ToList();
  75.  
  76.             Console.WriteLine($"Highest Average Salary: {department}");
  77.  
  78.             foreach (var men in listOfEmployees)
  79.             {
  80.                 Console.WriteLine($"{men.Name} {men.Salary:f2}");
  81.             }
  82.            
  83.            
  84.         }
  85.     }
  86.  
  87.    
  88.     class Employee
  89.     {
  90.         public string Name { get; set; }
  91.         public double Salary { get; set; }
  92.         public string Department { get; set; }
  93.  
  94.         public Employee(string name, double salary, string department)
  95.         {
  96.             this.Name = name;
  97.             this.Salary = salary;
  98.             this.Department = department;
  99.         }
  100.     }
  101. }
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