Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- static void Main()
- {
- List<Employee> register = new List<Employee>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] data = Console.ReadLine().Split();
- string name = data[0];
- decimal salary = decimal.Parse(data[1]);
- string position = data[2];
- string department = data[3];
- if (data.Length == 4)
- {
- var newEmployee = new Employee(name, salary, position, department);
- register.Add(newEmployee);
- }
- else if (data.Length == 5)
- {
- if (data[4].Contains("@"))
- {
- string email = data[4];
- var newEmployee = new Employee(name, salary, position, department, email);
- register.Add(newEmployee);
- }
- else
- {
- int age = int.Parse(data[4]);
- var newEmployee = new Employee(name, salary, position, department, age);
- register.Add(newEmployee);
- }
- }
- else if (data.Length == 6)
- {
- string email = data[4];
- int age = int.Parse(data[5]);
- var newEmployee = new Employee(name, salary, position, department, email, age);
- register.Add(newEmployee);
- }
- }
- var highest = register.GroupBy(e => e.Department)
- .Select(group => new
- {
- Dep = group.Key,
- Avg = group.Average(e => e.Salary)
- })
- .OrderByDescending(g => g.Avg)
- .FirstOrDefault();
- Console.WriteLine($"Highest Average Salary: {highest.Dep}");
- foreach (var emp in register.Where(e => e.Department == highest.Dep).OrderByDescending(e => e.Salary))
- {
- Console.WriteLine(emp);
- }
- }
- }
- public class Employee
- {
- public string Name { get; set; }
- public decimal Salary { get; set; }
- public string Position { get; set; }
- public string Department { get; set; }
- public string Email { get; set; }
- public int Age { get; set; }
- public Employee(string name, decimal salary, string position, string department)
- : this(name, salary, position, department, "n/a", -1)
- {
- }
- public Employee(string name, decimal salary, string position, string department, string email)
- : this(name, salary, position, department, email, -1)
- {
- }
- public Employee(string name, decimal salary, string position, string department, int age)
- : this(name, salary, position, department, "n/a", age)
- {
- }
- public Employee(string name, decimal salary, string position, string department, string email, int age)
- {
- this.Name = name;
- this.Salary = salary;
- this.Position = position;
- this.Department = department;
- this.Email = email;
- this.Age = age;
- }
- public override string ToString()
- {
- return $"{this.Name} {this.Salary} {this.Email} {this.Age}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement