Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CSharpPreparation
- {
- public class User
- {
- public User(string name)
- {
- this.Name = name;
- this.Position = string.Empty;
- this.Age = -1;
- this.Salary = -1;
- }
- public string Name { get; }
- public string Position { get; set; }
- public int Age { get; set; }
- public double Salary { get; set; }
- public override string ToString()
- {
- return $"Name: {this.Name}";
- }
- }
- public class Program
- {
- private static void Main(string[] args)
- {
- var input = Console.ReadLine();
- var withPosition = new Dictionary<string, User>();
- var withSalary = new Dictionary<string, User>();
- var withAge = new Dictionary<string, User>();
- while (input != "filter base")
- {
- var tokens = input.Split(new[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
- var username = tokens[0];
- int age = 0;
- double salary = 0;
- bool isAge = int.TryParse(tokens[1], out age);
- bool isSalary = double.TryParse(tokens[1], out salary);
- var user = new User(username);
- if (isAge)
- {
- user.Age = age;
- withAge.Add(username, user);
- }
- else if (isSalary)
- {
- user.Salary = salary;
- withSalary.Add(username, user);
- }
- else
- {
- user.Position = tokens[1];
- withPosition.Add(username, user);
- }
- input = Console.ReadLine();
- }
- var filter = Console.ReadLine();
- if (filter == "Position")
- {
- foreach (var user in withPosition)
- {
- Console.WriteLine(user.Value);
- Console.WriteLine($"Position: {user.Value.Position}");
- Console.WriteLine(new string('=', 20));
- }
- }
- else if (filter == "Salary")
- {
- foreach (var user in withSalary)
- {
- Console.WriteLine(user.Value);
- Console.WriteLine($"Salary: {user.Value.Salary:F2}");
- Console.WriteLine(new string('=', 20));
- }
- }
- else
- {
- foreach (var user in withAge)
- {
- Console.WriteLine(user.Value);
- Console.WriteLine($"Age: {user.Value.Age}");
- Console.WriteLine(new string('=', 20));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement