Advertisement
Guest User

Employees

a guest
Oct 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace DefiningClasses
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             List<Employee> employees = new List<Employee>();
  13.  
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string[] currEmployee = Console.ReadLine()
  17.                 .Split(' ')
  18.                 .ToArray();
  19.  
  20.                 Employee emp = new Employee(currEmployee[0], decimal.Parse(currEmployee[1]), currEmployee[2], currEmployee[3]);
  21.  
  22.                 if (currEmployee.Length == 5)
  23.                 {
  24.                     if (currEmployee[4].Contains('@'))
  25.                         {
  26.                             emp.Email = currEmployee[4];
  27.                         }
  28.                     else
  29.                         {
  30.                             emp.Age = int.Parse(currEmployee[4]);
  31.                         }
  32.                 }
  33.                 else if (currEmployee.Length == 6)
  34.                 {
  35.                     emp.Email = currEmployee[4];
  36.                     emp.Age = int.Parse(currEmployee[5]);
  37.                 }
  38.  
  39.                 employees.Add(emp);
  40.             }
  41.  
  42.             var topDept = employees.GroupBy(x => x.Department)
  43.                 .ToDictionary(x => x.Key, y => y.Select(s => s))
  44.                 .OrderByDescending(x => x.Value.Average(s => s.Salary))
  45.                 .FirstOrDefault();
  46.  
  47.             Console.WriteLine("Highest Average Salary: " + topDept.Key);
  48.  
  49.             foreach (var em in topDept.Value.OrderByDescending(x => x.Salary))
  50.             {
  51.                 Console.WriteLine($"{em.Name} {em.Salary} {em.Email} {em.Age}");
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement