Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class StartUp
- {
- //private static readonly IFormatProvider result;
- static void Main(string[] args)
- {
- List<Employee> employees = new List<Employee>();
- int n = Int32.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split();
- string name = input[0];
- decimal salary = decimal.Parse(input[1]);
- string position = input[2];
- string department = input[3];
- Employee employee = new Employee(name, salary, position, department);
- if (input.Length == 5)
- {
- if (int.TryParse(input[4], out int result))
- {
- employee.Age = result;
- }
- else
- {
- employee.Email = input[4];
- }
- }
- else if (input.Length == 6)
- {
- int age = int.Parse(input[5]);
- employee.Email = input[4];
- employee.Age = age;
- }
- employees.Add(employee);
- var topDepartment = 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: {topDepartment.Key}");
- foreach(var employee in topDepartment.Value.OrderByDescending(x => x.Salary))
- {
- Console.WriteLine($"{employee.Name} {employee.Salary} {employee.Position} {employee.Email} {employee.Age} ");
- }
- }
- }
- }
- class Employee
- {
- private string name;
- private string department;
- private string position;
- private int age;
- private decimal salary;
- private string email;
- public Employee(string name, decimal salary, string position, string department)
- {
- this.Name = name;
- this.Position = position;
- this.Department = department;
- this.Salary = salary;
- this.Age = -1;
- this.Email = "n/a";
- }
- public string Name
- {
- get { return this.name; }
- set { this.name = value; }
- }
- public string Position
- {
- get { return this.position; }
- set { this.position = value; }
- }
- public string Department
- {
- get { return this.department;}
- set { this.department = value; }
- }
- public decimal Salary
- {
- get { return this.salary; }
- set { this.salary = value; }
- }
- public int Age
- {
- get { return this.age; }
- set { this.age = value; }
- }
- public string Email
- {
- get { return this.email; }
- set { this.email = value; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement