Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace HelloFrance
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<string> listOfItems = Console.ReadLine().Split('|').ToList();
- double leftMoney = double.Parse(Console.ReadLine());
- List<double> listOfBoughtItemsOnlyPrices = new List<double>();
- List<double> listOfNewPricesAfterSold = new List<double>().ToList();
- for (int i = 0; i < listOfItems.Count; i++)
- {
- List<string> itemWithPrice = listOfItems[i].Split("->").ToList();
- string currentItem = itemWithPrice[0];
- double currentPrice = double.Parse(itemWithPrice[1]);
- if (currentItem == "Clothes" && currentPrice <= 50.00 && leftMoney >= currentPrice)
- {
- leftMoney -= currentPrice;
- listOfBoughtItemsOnlyPrices.Add(currentPrice);
- listOfNewPricesAfterSold.Add(currentPrice + (0.40 * currentPrice));
- }
- else if (currentItem == "Shoes" && currentPrice <= 35.00 && leftMoney >= currentPrice)
- {
- leftMoney -= currentPrice;
- listOfBoughtItemsOnlyPrices.Add(currentPrice);
- listOfNewPricesAfterSold.Add(currentPrice + (0.40 * currentPrice));
- }
- else if (currentItem == "Accessories" && currentPrice <= 20.50 && leftMoney >= currentPrice)
- {
- leftMoney -= currentPrice;
- listOfBoughtItemsOnlyPrices.Add(currentPrice);
- listOfNewPricesAfterSold.Add(currentPrice + (0.40 * currentPrice));
- }
- }
- foreach (var item in listOfNewPricesAfterSold)
- {
- Console.Write($"{item:F2} "); // never use Math.Round in this case, because in VS Console.WriteLine(Math.Round(0.005, 2)) gives 0, but Console.WriteLine($"{0.005:F2}") gives 0.01;
- }
- Console.WriteLine();
- double profit = listOfNewPricesAfterSold.Sum() - listOfBoughtItemsOnlyPrices.Sum();
- Console.WriteLine($"Profit: {profit:F2}");
- double allMoney = leftMoney + listOfNewPricesAfterSold.Sum();
- if (allMoney >= 150)
- {
- Console.WriteLine("Hello, France!");
- }
- else
- {
- Console.WriteLine("Time to go.");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment