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;
- using System.Numerics;
- using System.Threading.Tasks;
- using System.Collections;
- using System.Globalization;
- using System.Text.RegularExpressions;
- namespace ConsoleApp
- {
- class Program
- {
- static void Main()
- {
- string input = Console.ReadLine();
- var patern = new Regex (@"^%(?<name>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>\d+)\|[^|$%.]*?(?<price>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\$");
- double totalIncome = 0;
- while (input != "end of shift")
- {
- if (patern.IsMatch(input))
- {
- var match = patern.Matches(input);
- foreach (Match item in match)
- {
- string name = item.Groups["name"].Value;
- string productName = item.Groups["product"].Value;
- int count = int.Parse(item.Groups["count"].Value);
- double price = double.Parse(item.Groups["price"].Value);
- totalIncome += count * price;
- double ownPrice = count * price;
- Console.WriteLine($"{name}: {productName} - {ownPrice:f2}");
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"Total income: {totalIncome:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement