Facebook
From Soft Lion, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 47
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _03._Problem
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string pattern = @"^%(?<customer>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>\d+)\|[^|$%.]*?(?<price>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\$";
  11.             double totalIncome = 0;
  12.  
  13.             while (true)
  14.             {
  15.                 var line = Console.ReadLine();
  16.  
  17.                 if (line == "end of shift")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 if (Regex.IsMatch(line, pattern))
  23.                 {
  24.                     Match match = Regex.Match(line, pattern);
  25.                     var customer = match.Groups["customer"].Value;
  26.                     string product = match.Groups["product"].Value;
  27.                     int count = int.Parse(match.Groups["count"].Value);
  28.                     double price = double.Parse(match.Groups["price"].Value);
  29.                     double money = price * count;
  30.                     Console.WriteLine($"{customer}: {product} - {money:F2}");
  31.                     totalIncome += money;
  32.                 }
  33.             }
  34.             Console.WriteLine($"Total income: {totalIncome:F2}");
  35.         }
  36.     }
  37. }