Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- namespace text
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- var regex = new Regex(@">>([A-Z][a-zA-Z]+)<<([0-9]+(?:\.[0-9]+)?)!([0-9]+)");
- var listFurniture = new List<string>();
- decimal totalPrice = 0;
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "Purchase")
- {
- Match match = regex.Match(input);
- if (match.Success)
- {
- string furniture = $"{ match.Groups[1].Value}";
- listFurniture.Add(furniture);
- string price = $"{match.Groups[2].Value}";
- decimal priceDecimal = decimal.Parse(price);
- string quantity = $"{match.Groups[3].Value}";
- decimal quantityDecimal = decimal.Parse(quantity);
- totalPrice += priceDecimal * quantityDecimal;
- }
- }
- Console.WriteLine("Bought furniture:");
- foreach (var furniture in listFurniture)
- {
- Console.WriteLine(furniture);
- }
- Console.WriteLine($"Total money spend: {totalPrice:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement