Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace text
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- var regex = new Regex(@"%(?<name>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<quantity>[0-9]{1,})\|[^|$%.]*?(?<price>[0-9]+(?:\.[0-9]+)?)\$$");
- decimal totalIncome = 0;
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "end of shift")
- {
- var matches = regex.Matches(input);
- if (regex.IsMatch(input))
- {
- foreach (Match match in matches)
- {
- string quantity = match.Groups["quantity"].Value;
- int quantityInt = int.Parse(quantity);
- string price = match.Groups["price"].Value;
- decimal priceDecimal = decimal.Parse(price);
- decimal totalPrice = quantityInt * priceDecimal;
- Console.WriteLine($"{match.Groups["name"]}: {match.Groups["product"]} - {totalPrice:F2}");
- totalIncome += totalPrice;
- }
- }
- }
- Console.WriteLine($"Total income: {totalIncome:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement