Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace DefiningClasses
- {
- public class StartUp
- {
- public static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<Employee> employees = new List<Employee>();
- for (int i = 0; i < n; i++)
- {
- string[] currEmployee = Console.ReadLine()
- .Split(' ')
- .ToArray();
- Employee emp = new Employee(currEmployee[0], decimal.Parse(currEmployee[1]), currEmployee[2], currEmployee[3]);
- if (currEmployee.Length == 5)
- {
- if (currEmployee[4].Contains('@'))
- {
- emp.Email = currEmployee[4];
- }
- else
- {
- emp.Age = int.Parse(currEmployee[4]);
- }
- }
- else if (currEmployee.Length == 6)
- {
- emp.Email = currEmployee[4];
- emp.Age = int.Parse(currEmployee[5]);
- }
- employees.Add(emp);
- }
- var topDept = employees.GroupBy(x => x.Department)
- .ToDictionary(x => x.Key, y => y.Select(s => s))
- .OrderByDescending(x => x.Value.Average(s => s.Salary))
- .FirstOrDefault();
- Console.WriteLine("Highest Average Salary: " + topDept.Key);
- foreach (var em in topDept.Value.OrderByDescending(x => x.Salary))
- {
- Console.WriteLine($"{em.Name} {em.Salary} {em.Email} {em.Age}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement