using System.Collections.Generic;
public static Dictionary<string, int> AverageAgeForEachCompany(List<Employee> employees)
var result = new Dictionary<string,int>();
foreach(var company in employees.Select(x => x.Company).Distinct().OrderBy(x => x))
result.Add(company, (int)Math.Round(employees.Where(x => x.Company == company).Average(y => y.Age),0));
Console.WriteLine(result);
public static Dictionary<string, int> CountOfEmployeesForEachCompany(List<Employee> employees)
var result = new Dictionary<string,int>();
foreach(var e in employees.Select(x=> x.Company).Distinct().OrderBy(x=>x))
result.Add(e,employees.Where(x => x.Company == e).Count());
public static Dictionary<string, Employee> OldestAgeForEachCompany(List<Employee> employees)
{var result = new Dictionary<string,Employee>();
foreach(var c in employees.Select(x=>x.Company).Distinct().OrderBy(x=>x))
result.Add(c, employees.Where(x=> x.Company == c).OrderByDescending(y=>y.Age).First());
public static void Main()
int countOfEmployees = int.Parse(Console.ReadLine());
var employees = new List<Employee>();
for (int i = 0; i < countOfEmployees; i++)
string str = Console.ReadLine();
string[] strArr = str.Split(' ');
employees.Add(new Employee {
Age = int.Parse(strArr[3])
foreach (var emp in AverageAgeForEachCompany(employees))
Console.WriteLine($"The average age for company {emp.Key} is {emp.Value}");
foreach (var emp in CountOfEmployeesForEachCompany(employees))
Console.WriteLine($"The count of employees for company {emp.Key} is {emp.Value}");
foreach (var emp in OldestAgeForEachCompany(employees))
Console.WriteLine($"The oldest employee of company {emp.Key} is {emp.Value.FirstName} {emp.Value.LastName} having age {emp.Value.Age}");
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string Company { get; set; }