Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CompanyRoster
- {
- public class CompanyRoster
- {
- public static void Main(string[] args)
- {
- HashSet<string> departments = new HashSet<string>();
- List<Employee> employees = new List<Employee>();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] tokens = Console.ReadLine()
- .Split(new char[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
- string name = tokens[0];
- decimal salary = decimal.Parse(tokens[1]);
- string position = tokens[2];
- string department = tokens[3];
- Employee emp = new Employee(name, salary, position, department);
- if (tokens.Length == 5)
- {
- if (tokens[4].Contains("@"))
- {
- emp.email = tokens[4];
- }
- else
- {
- int age;
- bool isNumber = int.TryParse(tokens[4], out age);
- if (isNumber)
- {
- emp.age = age;
- }
- }
- }
- else if (tokens.Length == 6)
- {
- emp.email = tokens[4];
- emp.age = int.Parse(tokens[5]);
- }
- employees.Add(emp);
- departments.Add(department);
- }
- decimal avgMaxSalary = 0;
- string maxSalaryDepartment = string.Empty;
- foreach (var dep in departments)
- {
- decimal avgSalary = 0;
- int emps = 0;
- foreach (var emp in employees)
- {
- if (emp.department == dep)
- {
- emps++;
- avgSalary += emp.salary;
- }
- }
- avgSalary /= emps;
- if (avgSalary > avgMaxSalary)
- {
- avgMaxSalary = avgSalary;
- maxSalaryDepartment = dep;
- }
- }
- Console.WriteLine("Highest Average Salary: {0}", maxSalaryDepartment);
- employees = employees
- .Where(emp => emp.department == maxSalaryDepartment)
- .OrderByDescending(emp => emp.salary)
- .ToList();
- foreach (var emp in employees)
- {
- Console.WriteLine("{0} {1:F2} {2} {3}",
- emp.name, emp.salary, emp.email, emp.age);
- }
- }
- }
- public class Employee
- {
- public string name;
- public decimal salary;
- public string position;
- public string department;
- public string email { get; set; }
- public int age { get; set; }
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement