Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- public class Employee
- {
- //mantadory
- public string name;
- public decimal salary;
- public string position;
- public string department;
- //optional
- public string email;
- public int age;
- public Employee(string name, decimal salary, string position, string department)
- {
- this.name = name;
- this.salary = salary;
- this.position = position;
- this.department = department;
- this.email = "n/a";
- this.age = -1;
- }
- public Employee(string email, string name, decimal salary, string position, string department)
- : this(name, salary, position, department)
- {
- this.email = email;
- }
- public Employee(int age, string email, string name, decimal salary, string position, string department)
- : this(email, name, salary, position, department)
- {
- this.age = age;
- }
- }
- public class CompanyRoster
- {
- public static void Main()
- {
- var numberOfEmployess = int.Parse(Console.ReadLine());
- var lstEmployess = new List<Employee>();
- for (int i = 0; i < numberOfEmployess; i++)
- {
- var inputEmployess = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var employee = new Employee(inputEmployess[0], decimal.Parse(inputEmployess[1]), inputEmployess[2], inputEmployess[3]);
- if (inputEmployess.Length == 5)
- {
- if (inputEmployess[4].Contains("@"))
- {
- employee.email = inputEmployess[4];
- }
- else
- {
- employee.age = int.Parse(inputEmployess[4]);
- }
- }
- else if (inputEmployess.Length == 6)
- {
- employee.email = inputEmployess[4];
- employee.age = int.Parse(inputEmployess[5]);
- }
- lstEmployess.Add(employee);
- }
- var result = lstEmployess
- .GroupBy(e => e.department)
- .Select(e => new
- {
- Department = e.Key,
- Salary = e.Average(emp => emp.salary),
- Employess = e.OrderByDescending(emp => emp.salary)
- })
- .OrderByDescending(e=>e.Salary)
- .FirstOrDefault();
- Console.WriteLine($"Highest Average Salary: {result.Department}");
- foreach (var employe in result.Employess)
- {
- Console.WriteLine($"{employe.name} {employe.salary:F2} {employe.email} {employe.age}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement