Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Numerics;
  6. using System.Threading.Tasks;
  7. using System.Collections;
  8. using System.Globalization;
  9. using System.Text.RegularExpressions;
  10.  
  11.  
  12. namespace ConsoleApp
  13. {
  14. class Program
  15. {
  16. static void Main()
  17. {
  18. string input = Console.ReadLine();
  19. var patern = new Regex (@"^%(?<name>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>\d+)\|[^|$%.]*?(?<price>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)\$");
  20. double totalIncome = 0;
  21.  
  22. while (input != "end of shift")
  23. {
  24.  
  25. if (patern.IsMatch(input))
  26. {
  27. var match = patern.Matches(input);
  28. foreach (Match item in match)
  29. {
  30. string name = item.Groups["name"].Value;
  31. string productName = item.Groups["product"].Value;
  32. int count = int.Parse(item.Groups["count"].Value);
  33. double price = double.Parse(item.Groups["price"].Value);
  34. totalIncome += count * price;
  35. double ownPrice = count * price;
  36.  
  37. Console.WriteLine($"{name}: {productName} - {ownPrice:f2}");
  38. }
  39.  
  40. }
  41.  
  42. input = Console.ReadLine();
  43. }
  44. Console.WriteLine($"Total income: {totalIncome:F2}");
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement