Advertisement
knoteva

Untitled

Jul 19th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _03._SoftUni_Bar_Income
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input;
  13.             //string regex = @"^%(?<name>[A-Z][a-z]*)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>[0-9]+)\|[^|$%.]*?(?<price>[0-9]+\.*[0-9]*)\$$";
  14.             //string regex = @"(?<customer>%[A-Z][a-z]+%)[^|$%.]*(?<product><\w+>)[^|$%.]*(?<count>\|[0-9]+\|)[^|$%.]*(?<price>\d+\.*\d+)\$";
  15.             string regex = @"%(?<customer>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>[0-9]+)\|[^|$%.]*?(?<price>\d+\.*\d+)\$";
  16.  
  17.             double totalPricePerName = 0;
  18.             double totalPrice = 0;
  19.  
  20.             while ((input = Console.ReadLine()) != "end of shift")
  21.             {
  22.                 MatchCollection matched = Regex.Matches(input, regex);
  23.                 foreach (Match m in matched)
  24.                 {
  25.                     var name = m.Groups["customer"].Value;
  26.                     var product = m.Groups["product"].Value;
  27.                     var count = int.Parse(m.Groups["count"].Value);
  28.                     var price = double.Parse(m.Groups["price"].Value);
  29.  
  30.  
  31.                     totalPricePerName = price * count;
  32.                     totalPrice += totalPricePerName;
  33.                     Console.WriteLine($"{name}: {product} - {totalPricePerName:F2}");
  34.  
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine($"Total income: {totalPrice:F2}");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement