Advertisement
nikolayneykov

Untitled

Mar 11th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         const decimal clothesMaxPrice = 50;
  10.         const decimal shoesMaxPrice = 35;
  11.         const decimal accessoriesMaxPrice = 20.5m;
  12.  
  13.         string[] items = Console.ReadLine().Split('|');
  14.         decimal budget = decimal.Parse(Console.ReadLine());
  15.         List<decimal> boughtItemPrices = new List<decimal>();
  16.  
  17.         foreach (var item in items)
  18.         {
  19.             string[] tokens = item.Split("->", StringSplitOptions.RemoveEmptyEntries);
  20.             string type = tokens[0];
  21.             decimal price = decimal.Parse(tokens[1]);
  22.  
  23.             if ((type == "Clothes" && price <= clothesMaxPrice && budget - price >= 0) ||
  24.                 (type == "Shoes" && price <= shoesMaxPrice && budget - price >= 0) ||
  25.                 (type == "Accessories" && price <= accessoriesMaxPrice && budget - price >= 0))
  26.             {
  27.                 budget -= price;
  28.                 boughtItemPrices.Add(price);
  29.             }
  30.         }
  31.  
  32.         decimal oldSum = boughtItemPrices.Sum();
  33.         boughtItemPrices = boughtItemPrices.Select(e => e *= 1.4m).ToList();
  34.         decimal newSum = boughtItemPrices.Sum();
  35.         decimal profit = newSum - oldSum;
  36.  
  37.         Console.WriteLine(string.Join(" ", boughtItemPrices.Select(x => x.ToString("F2"))));
  38.         Console.WriteLine($"Profit: {profit:F2}");
  39.         Console.WriteLine(budget + newSum >= 150 ? "Hello, France!" : "Time to go.");
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement