Advertisement
terlichki

Untitled

Jul 3rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Numerics;
  9. using System.Text.RegularExpressions;
  10.  
  11. namespace ProblemThreeExam
  12. {
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. string income = Console.ReadLine();
  18. string patern= @"%([A-Z][a-z]+)%[^(|$%.)]*<(\w+)>[^(|$%.)]*\|([0-9]+)\|[^(|$%.0-9)]*([0-9]+.?[0-9]*)\$";
  19. List<string> arr= new List<string>();
  20. Regex reg = new Regex(patern);
  21. double total = 0;
  22.  
  23. while (income!="end of shift")
  24. {
  25.  
  26. Match m = reg.Match(income);
  27.  
  28. if (m.Success)
  29. {
  30. string name = m.Groups[1].Value.Trim('%');
  31. string product = m.Groups[2].Value.Trim('>');
  32. int quantity = int.Parse(m.Groups[3].Value.Trim('|'));
  33. double price = double.Parse(m.Groups[4].Value.Trim('$'));
  34. double sum = (quantity * price);
  35. total += sum;
  36. string toAdd = ($"{name}: {product} - {sum:f2}");
  37. arr.Add(toAdd);
  38. }
  39.  
  40. income = Console.ReadLine();
  41. }
  42.  
  43. foreach (var item in arr)
  44. {
  45. Console.WriteLine(string.Join(" ",item));
  46. }
  47.  
  48. Console.WriteLine($"Total income: {total:f2}");
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement