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