Advertisement
GabrielDas

Kalincho

Nov 21st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.29 KB | None | 0 0
  1. class StartUp
  2.     {
  3.         //private static readonly IFormatProvider result;
  4.  
  5.         static void Main(string[] args)
  6.         {
  7.             List<Employee> employees = new List<Employee>();
  8.  
  9.             int n = Int32.Parse(Console.ReadLine());
  10.  
  11.             for (int i = 0; i < n; i++)
  12.             {
  13.                 string[] input = Console.ReadLine().Split();
  14.  
  15.                 string name = input[0];
  16.                 decimal salary = decimal.Parse(input[1]);
  17.                 string position = input[2];
  18.                 string department = input[3];
  19.  
  20.                 Employee employee = new Employee(name, salary, position, department);
  21.  
  22.                 if (input.Length == 5)
  23.                 {
  24.                     if (int.TryParse(input[4], out int result))
  25.                     {
  26.                        
  27.                         employee.Age = result;
  28.                     }
  29.                     else
  30.                     {
  31.                      
  32.                         employee.Email = input[4];
  33.                     }
  34.                 }
  35.                 else if (input.Length == 6)
  36.                 {
  37.                     int age = int.Parse(input[5]);
  38.                     employee.Email = input[4];
  39.                     employee.Age = age;
  40.                 }
  41.  
  42.                 employees.Add(employee);
  43.  
  44.                 var topDepartment = employees.GroupBy(x => x.Department)
  45.                     .ToDictionary(x => x.Key, y => y.Select(s => s))
  46.                     .OrderByDescending(x => x.Value.Average(s => s.Salary))
  47.                     .FirstOrDefault();
  48.  
  49.                 Console.WriteLine($" Highest Average Salary: {topDepartment.Key}");
  50.  
  51.                 foreach(var employee in topDepartment.Value.OrderByDescending(x => x.Salary))
  52.                 {
  53.                     Console.WriteLine($"{employee.Name} {employee.Salary} {employee.Position} {employee.Email} {employee.Age} ");
  54.  
  55.                 }
  56.             }
  57.         }
  58.     }
  59.  
  60. class Employee
  61.     {
  62.         private string name;
  63.         private string department;
  64.         private string position;
  65.         private int age;
  66.         private decimal salary;
  67.         private string email;
  68.  
  69.         public Employee(string name, decimal salary, string position, string department)
  70.         {
  71.  
  72.             this.Name = name;
  73.             this.Position = position;
  74.             this.Department = department;
  75.             this.Salary = salary;
  76.             this.Age = -1;
  77.             this.Email = "n/a";
  78.  
  79.  
  80.         }
  81.  
  82.         public string Name
  83.         {
  84.             get { return this.name; }
  85.             set { this.name = value; }
  86.         }
  87.  
  88.         public string Position
  89.         {
  90.             get { return this.position; }
  91.             set { this.position = value; }
  92.         }
  93.  
  94.         public string Department
  95.         {
  96.             get { return this.department;}
  97.             set { this.department = value; }
  98.  
  99.         }
  100.  
  101.         public decimal Salary
  102.         {
  103.             get { return this.salary; }
  104.             set { this.salary = value; }
  105.  
  106.         }
  107.  
  108.         public int Age
  109.         {
  110.             get { return this.age; }
  111.             set { this.age = value; }
  112.  
  113.         }
  114.  
  115.         public string Email
  116.         {
  117.             get { return this.email; }
  118.             set { this.email = value; }
  119.  
  120.         }
  121.  
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement