Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace SoftUniBarIncome
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Regex pattern = new Regex(@"%(?<name>[A-Z][a-z]*)%[^|$%.]*?<(?<product>\w+)>[^|$%.]*?\|(?<quantity>\d+)\|[^|$%.]*?(?<price>\d+(\.\d+)?)\$");
- double total = 0;
- string command;
- while ((command = Console.ReadLine()) != "end of shift")
- {
- if (pattern.IsMatch(command))
- {
- var info = pattern.Match(command);
- string name = info.Groups["name"].Value;
- string product = info.Groups["product"].Value;
- int quantity = int.Parse(info.Groups["quantity"].Value);
- double price = double.Parse(info.Groups["price"].Value);
- Console.WriteLine($"{name}: {product} - {price * quantity:f2}");
- total += price * quantity;
- }
- }
- Console.WriteLine($"Total income: {total:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement