Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _03._SoftUni_Bar_Income
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input;
- //string regex = @"^%(?<name>[A-Z][a-z]*)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>[0-9]+)\|[^|$%.]*?(?<price>[0-9]+\.*[0-9]*)\$$";
- //string regex = @"(?<customer>%[A-Z][a-z]+%)[^|$%.]*(?<product><\w+>)[^|$%.]*(?<count>\|[0-9]+\|)[^|$%.]*(?<price>\d+\.*\d+)\$";
- string regex = @"%(?<customer>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>[0-9]+)\|[^|$%.]*?(?<price>\d+\.*\d+)\$";
- double totalPricePerName = 0;
- double totalPrice = 0;
- while ((input = Console.ReadLine()) != "end of shift")
- {
- MatchCollection matched = Regex.Matches(input, regex);
- foreach (Match m in matched)
- {
- var name = m.Groups["customer"].Value;
- var product = m.Groups["product"].Value;
- var count = int.Parse(m.Groups["count"].Value);
- var price = double.Parse(m.Groups["price"].Value);
- totalPricePerName = price * count;
- totalPrice += totalPricePerName;
- Console.WriteLine($"{name}: {product} - {totalPricePerName:F2}");
- }
- }
- Console.WriteLine($"Total income: {totalPrice:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement