private static void Readinput() { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string line = Console.ReadLine(); string[] splitted = line.Split('-'); Position pos = new Position(); pos.PositionName = splitted[0].Trim(); pos.Value = int.Parse(splitted[1].Trim()); Positions.Add(pos); } int m = int.Parse(Console.ReadLine()); for (int i = 0; i < m; i++) { string line = Console.ReadLine(); string[] splitted = line.Split('-'); Employees employee = new Employees(); string name = splitted[0]; string[] Names = name.Split(' '); employee.FirstName = Names[0]; employee.SecondName = Names[1]; employee.Position = splitted[1]; EmployeesList.Add(employee); } }
static void SortEmployees(List<Employees> employees) { int prevPos = 0; List<Employees> tempEmpl = new List<Employees>(); foreach (var pos in Positions) { for (int i = 0; i < employees.Count; i++) { if (i > 0) prevPos = i - 1; if (pos.PositionName == employees[i].Position.Trim()) { Employees empl = new Employees(); empl.Position = employees[i].Position; empl.FirstName = employees[i].FirstName; empl.SecondName = employees[i].SecondName; if (empl.Position == employees[prevPos].Position && i > 0) { SortedEmployees.RemoveAt(SortedEmployees.Count - 1); tempEmpl.Add(employees[i]); tempEmpl.Add(employees[prevPos]); tempEmpl.Sort((a, b) => a.SecondName.CompareTo(b.SecondName)); foreach (var worker in tempEmpl) { if (!SortedEmployees.Contains(worker)) { SortedEmployees.Add(worker); } } } else { if (!SortedEmployees.Contains(empl)) { SortedEmployees.Add(empl); } } } } } }