Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace _3.Employees
- {
- class Employees
- {
- private static void ConsolePositionsReader(Dictionary<string, int> positions)
- {
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] inputs = Console.ReadLine().Split('-');
- InputPositionReader(positions, inputs);
- }
- }
- private static void FilePositionsReader(Dictionary<string, int> positions)
- {
- StreamReader textReader = new StreamReader(@"../../Positions.txt");
- using (textReader)
- {
- int n = int.Parse(textReader.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string[] inputs = textReader.ReadLine().Split('-');
- InputPositionReader(positions, inputs);
- }
- }
- }
- private static void InputPositionReader(Dictionary<string, int> positions, string[] inputs)
- {
- string name = inputs[0].Remove(inputs[0].Length - 1);
- int value = int.Parse(inputs[1].Remove(0, 1));
- if (positions.ContainsKey(name))
- {
- //positions[name] = value;
- }
- else
- {
- positions.Add(name, value);
- }
- }
- private static void ConsoleEmployeesReader(Dictionary<string, int> positions, List<Employee> AllEmployees)
- {
- int m = int.Parse(Console.ReadLine());
- for (int i = 0; i < m; i++)
- {
- string[] inputs = Console.ReadLine().Split('-');
- InputEmployeesReader(positions, AllEmployees, inputs);
- }
- }
- private static void FileEmployeesReader(Dictionary<string, int> positions, List<Employee> AllEmployees)
- {
- StreamReader textReader = new StreamReader(@"../../Employees.txt");
- using (textReader)
- {
- int m = int.Parse(textReader.ReadLine());
- for (int i = 0; i < m; i++)
- {
- string[] inputs = textReader.ReadLine().Split('-');
- InputEmployeesReader(positions, AllEmployees, inputs);
- }
- }
- }
- private static void InputEmployeesReader(Dictionary<string, int> positions, List<Employee> AllEmployees, string[] inputs)
- {
- Employee newEmplyee = new Employee();
- string[] names = inputs[0].Remove(inputs[0].Length - 1).Split(' ');
- newEmplyee.FirstName = names[0];
- newEmplyee.LastName = names[1];
- newEmplyee.PositionRank = positions[inputs[1].Remove(0, 1)];
- AllEmployees.Add(newEmplyee);
- }
- private static void EmployeesChanger(List<Employee> AllEmployees, int i, int j)
- {
- Employee dublicate = new Employee();
- dublicate = AllEmployees[j];
- AllEmployees[j] = AllEmployees[i];
- AllEmployees[i] = dublicate;
- }
- private static void EmployeesSort(List<Employee> AllEmployees)
- {
- for (int i = 0; i < AllEmployees.Count; i++)
- {
- for (int j = i + 1; j < AllEmployees.Count; j++)
- {
- if (AllEmployees[j] > AllEmployees[i])
- {
- EmployeesChanger(AllEmployees, i, j);
- }
- }
- }
- }
- private static void EmployeesPrint(List<Employee> AllEmployees)
- {
- for (int i = 0; i < AllEmployees.Count; i++)
- {
- Console.WriteLine("{0} {1}",AllEmployees[i].FirstName,AllEmployees[i].LastName);
- }
- }
- static void Main(string[] args)
- {
- Dictionary<string, int> positions = new Dictionary<string, int>();
- ConsolePositionsReader(positions);
- //FilePositionsReader(positions);
- List<Employee> AllEmployees = new List<Employee>();
- ConsoleEmployeesReader(positions, AllEmployees);
- //FileEmployeesReader(positions, AllEmployees);
- EmployeesSort(AllEmployees);
- EmployeesPrint(AllEmployees);
- }
- }
- class Employee
- {
- private string firstName;
- private string lastName;
- private int positionRank;
- public string FirstName
- {
- get { return firstName; }
- set { firstName = value; }
- }
- public string LastName
- {
- get { return lastName; }
- set { lastName = value; }
- }
- public int PositionRank
- {
- get { return positionRank; }
- set { positionRank = value; }
- }
- public Employee()
- {
- firstName = "";
- lastName = "";
- positionRank = 0;
- }
- public Employee(string firstName, string lastName, int positionRank)
- {
- this.firstName = firstName;
- this.lastName = lastName;
- this.positionRank = positionRank;
- }
- public static bool operator >(Employee e1, Employee e2)
- {
- if (e1.positionRank == e2.positionRank)
- {
- if (String.Compare(e1.lastName, e2.lastName) == 1)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- return e1.positionRank > e2.positionRank;
- }
- public static bool operator <(Employee e1, Employee e2)
- {
- if (e1.positionRank == e2.positionRank)
- {
- if (String.Compare(e1.lastName, e2.lastName) == 1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- return e1.positionRank < e2.positionRank;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement