Advertisement
Aborigenius

FilterBase

Jul 13th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FilterBase
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, int> employeeAge = new Dictionary<string, int>();
  14.             Dictionary<string, double> employeeSalary = new Dictionary<string, double>();
  15.             Dictionary<string, string> employeePositions = new Dictionary<string, string>();
  16.  
  17.             string[] input = Console.ReadLine().Split(new char[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.  
  20.             while (input[0] != "filter")
  21.             {
  22.                 string name = input[0];
  23.                 string values = input[1];
  24.                 int age = 0;
  25.                 double salary = 0;
  26.                 if (int.TryParse(input[1], out age))
  27.                 {
  28.                     employeeAge[name] = age;
  29.                 }
  30.                 else if (double.TryParse(values, out salary))
  31.                 {
  32.                     employeeSalary[name] = salary;
  33.                 }
  34.                 else
  35.                 {
  36.                     employeePositions[name] = values;
  37.                 }
  38.               input = Console.ReadLine().Split(new char[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  39.  
  40.             }
  41.             string condition = Console.ReadLine().ToLower();
  42.             if (condition == "position")
  43.             {
  44.                 foreach (KeyValuePair<string, string> item in employeePositions)
  45.                 {
  46.                     Console.WriteLine($"Name: {item.Key}");
  47.                     Console.WriteLine($"Position: {item.Value}");
  48.                     Console.WriteLine(new string('=', 20));
  49.                 }
  50.             }
  51.             else if (condition == "age")
  52.             {
  53.                 foreach (KeyValuePair<string, int> item in employeeAge)
  54.                 {
  55.                     Console.WriteLine($"Name: {item.Key}");
  56.                     Console.WriteLine($"Age: {item.Value}");
  57.                     Console.WriteLine(new string('=', 20));
  58.                 }
  59.             }
  60.             else
  61.             {
  62.                 foreach (KeyValuePair<string, double> item in employeeSalary)
  63.                 {
  64.                     Console.WriteLine($"Name: {item.Key}");
  65.                     Console.WriteLine($"Salary: {item.Value:f2}");
  66.                     Console.WriteLine(new string('=', 20));
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement