Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- class Employees
- {
- static void Table(string[,] array)
- {
- DataTable dt = new DataTable();
- // first row contains column names:
- dt.Columns.Add("First Name");
- dt.Columns.Add("Family Name");
- dt.Columns.Add("Position");
- dt.Columns["Position"].DataType = typeof(int);
- // load data from string array to data table:
- for (int rowindex = 0; rowindex < array.GetLength(0); rowindex++)
- {
- DataRow row = dt.NewRow();
- for (int col = 0; col < array.GetLength(1); col++)
- {
- row[col] = array[rowindex, col];
- }
- dt.Rows.Add(row);
- }
- var viewDT = new DataView(dt);
- viewDT.Sort = "Position DESC, Family Name ASC, First Name ASC";
- foreach (DataRowView dr in viewDT)
- {
- Console.WriteLine("{0} {1}", dr[0], dr[1]);
- }
- }
- static void Main()
- {
- //Read position names and weights in a dictionary
- int numOfPositions = int.Parse(Console.ReadLine());
- Dictionary<string, string> positionTitles = new Dictionary<string, string>();
- for (int i = 0; i < numOfPositions; i++)
- {
- string input = Console.ReadLine();
- string[] temp = input.Split('-');
- if (!positionTitles.ContainsKey(temp[0].Trim()))
- {
- positionTitles.Add(temp[0].Trim(), temp[1].Trim());
- }
- }
- //Read the employee names
- int numOfEmployees = int.Parse(Console.ReadLine());
- string[,] employees = new string[numOfEmployees, 3];
- for (int i = 0; i < numOfEmployees; i++)
- {
- string input = Console.ReadLine();
- string[] temp = input.Split('-');
- string[] temp2 = temp[0].Split(' ');
- employees[i, 0] = temp2[0].Trim();//First name
- employees[i, 1] = temp2[1].Trim();//Family name
- employees[i, 2] = temp[1].Trim();//Position name
- string weight = "0";
- positionTitles.TryGetValue(employees[i, 2], out weight);//Match with the dictionary of Positions and exchange the values to get the number
- employees[i, 2] = weight;
- }
- Table(employees);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement