Advertisement
sashomaga

Employee sort

Jan 31st, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class Program
  7. {
  8.     static void Main()
  9.     {
  10.         int profCount = int.Parse(Console.ReadLine());
  11.         Dictionary<string, int> precedence = new Dictionary<string, int>();
  12.         string[] input = new string[profCount];
  13.         //char[] factor = {'-'};
  14.         for (int i = 0; i < profCount; i++)
  15.         {
  16.             input = Console.ReadLine().Split(new string[] { " - " }, StringSplitOptions.RemoveEmptyEntries);
  17.             if (!precedence.ContainsKey(input[0]))
  18.             {
  19.                    precedence.Add(input[0].Trim(), int.Parse(input[1]));
  20.             }                        
  21.         }
  22.  
  23.         int employeeCount = int.Parse(Console.ReadLine());
  24.         List<Employees> workers = new List<Employees>();
  25.         string[] data = new string[2];
  26.         string[] subData = new string[2];
  27.         //char[] subFactor = {' '};
  28.         for (int i = 0; i < employeeCount; i++)
  29.         {
  30.             data = Console.ReadLine().Split(new string[] {" - "},StringSplitOptions.RemoveEmptyEntries);
  31.  
  32.             subData = data[0].Split(new string[] {" "},StringSplitOptions.RemoveEmptyEntries);
  33.             Employees current = new Employees();
  34.             current.firstName = subData[0].Trim();
  35.             current.lastName = subData[1].Trim();
  36.             current.profession = data[1].Trim();
  37.             current.profPrecedence = precedence[current.profession];
  38.             workers.Add(current);
  39.         }
  40.         //sort
  41.         var sorted = workers.OrderByDescending(x => x.profPrecedence).ThenBy(x => x.lastName).ThenBy(x => x.firstName);
  42.  
  43.         //print
  44.         foreach (Employees item in sorted)
  45.         {
  46.             Console.WriteLine("{0} {1}",item.firstName, item.lastName);
  47.         }
  48.     }
  49.    
  50. }
  51.  
  52. class Employees
  53. {
  54.     public string profession;
  55.     public string firstName;
  56.     public string lastName;
  57.     public int profPrecedence;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement