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.Json;
- namespace SandBox
- {
- public class Product
- {
- public int id { get; set; }
- public string name { get; set; }
- public int price { get; set; }
- public string date { get; set; }
- }
- public class Program
- {
- static void Main(string[] args)
- {
- string inputJSON = Console.ReadLine();
- List<string> filtersList = new List<string>(5);
- for (int i = 0; i < 5; i++)
- {
- filtersList.Add(Console.ReadLine());
- }
- Dictionary<string, string> filtersDict = new Dictionary<string, string>(5);
- foreach (var filter in filtersList)
- {
- filtersDict.Add(filter.Split(' ')[0], filter.Split(' ')[1]);
- }
- List <Product> products= new List<Product>();
- products = JsonSerializer.Deserialize<List<Product>>(inputJSON);
- DateTime dateAfter = new DateTime(Convert.ToInt32(filtersDict["DATE_AFTER"].Split('.')[2]),
- Convert.ToInt32(filtersDict["DATE_AFTER"].Split('.')[1]),
- Convert.ToInt32(filtersDict["DATE_AFTER"].Split('.')[0]));
- DateTime dateBefore = new DateTime(Convert.ToInt32(filtersDict["DATE_BEFORE"].Split('.')[2]),
- Convert.ToInt32(filtersDict["DATE_BEFORE"].Split('.')[1]),
- Convert.ToInt32(filtersDict["DATE_BEFORE"].Split('.')[0]));
- List<Product> selectedProducts = new List<Product>();
- foreach (var product in products)
- {
- DateTime date = new DateTime(Convert.ToInt32(product.date.Split('.')[2]),
- Convert.ToInt32(product.date.Split('.')[1]),
- Convert.ToInt32(product.date.Split('.')[0]));
- if (product.name.ToLower().Contains(filtersDict["NAME_CONTAINS"].ToLower()) &&
- product.price >= Convert.ToInt32(filtersDict["PRICE_GREATER_THAN"]) &&
- product.price <= Convert.ToInt32(filtersDict["PRICE_LESS_THAN"]) &&
- date >= dateAfter && date <= dateBefore)
- {
- selectedProducts.Add(product);
- }
- }
- var sortedSelectedProducts = from p in selectedProducts orderby p.id select p;
- Console.WriteLine(JsonSerializer.Serialize(sortedSelectedProducts));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement