コード例 #1
0
 private static IEnumerable<Product> GetProductsInPriceRange(OrderedBag<Product> bag, decimal min, decimal max)
 {
     Product minProduct = bag.FirstOrDefault(p => p.Price >= min);
     Product maxProduct = bag.FirstOrDefault(p => p.Price >= max);
     var result = bag.Range(minProduct, true, maxProduct, false);
     return result.Take(20);
 }
コード例 #2
0
        private static IEnumerable <Product> GetProductsInPriceRange(OrderedBag <Product> bag, decimal min, decimal max)
        {
            Product minProduct = bag.FirstOrDefault(p => p.Price >= min);
            Product maxProduct = bag.FirstOrDefault(p => p.Price >= max);
            var     result     = bag.Range(minProduct, true, maxProduct, false);

            return(result.Take(20));
        }
コード例 #3
0
        private static IEnumerable<Product> GetProductsInRange(OrderedBag<Product> products, int min, int max, int count)
        {
            var fromProduct = products.FirstOrDefault(p => p.Price >= min);
            var toProduct = products.FirstOrDefault(p => p.Price <= max);

            var filteredProducts = products
                .Range(fromProduct, true, toProduct, true)
                .Take(count);

            return filteredProducts;
        }
コード例 #4
0
        private ICollection <Product> FindTopProductsByPrice(OrderedBag <Product> productList, double startPrice, double endPrice)
        {
            var firstProductStartPrice    = productList.FirstOrDefault(x => x.Price >= startPrice);
            var lastProductEndPrice       = productList.LastOrDefault(x => x.Price <= endPrice);
            var productsInRange           = productList.Range(firstProductStartPrice, true, lastProductEndPrice, true);
            var firstgivenProductsInRange = productsInRange.Take(ProductsInRangeCount);

            return(firstgivenProductsInRange.ToList());
        }
コード例 #5
0
        static IEnumerable<Product> GetProductsByPriceRange(OrderedBag<Product> products, decimal from, decimal to, int count)
        {
            var result = products.Range(
                    products.FirstOrDefault(x => x.Price >= from),
                    true,
                    products.LastOrDefault(x => x.Price <= to),
                    true).Take(count);

            return result;
        }
コード例 #6
0
        static void Main()
        {
            var commandsCount = int.Parse(Console.ReadLine());
            var taskList      = new OrderedBag <Task>(CompareTasks);
            var result        = new StringBuilder();

            for (int i = 0; i < commandsCount; i++)
            {
                string[] userLine = Console.ReadLine().Split(' ');

                string command = userLine[0];

                switch (command)
                {
                case "New":
                {
                    var newTask = new Task
                    {
                        Complexity = int.Parse(userLine[1]),
                        Name       = userLine[2]
                    };

                    taskList.Add(newTask);
                    break;
                }

                case "Solve":
                {
                    var solvedTask = taskList.FirstOrDefault();
                    taskList.Remove(solvedTask);
                    result.AppendLine(solvedTask == null ? "Rest" : solvedTask.Name);
                    break;
                }

                default:
                    throw new ArgumentException("Invalid command");
                }
            }

            Console.WriteLine(result.ToString());
        }
コード例 #7
0
 /// <summary>
 /// <paramref name="moment"/>와 같은 값을 가진 <see cref="TimeLineMoment"/>를 찾습니다.
 /// </summary>
 /// <param name="moment">찾고자하는 moment</param>
 /// <returns></returns>
 public ITimeLineMoment Find(DateTime moment)
 {
     return(_timeLineMoments.FirstOrDefault(tlm => Equals(tlm.Moment, moment)));
 }