Advertisement
AnastasiyaG

Untitled

Mar 19th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. namespace _1._Furniture
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. List<string> boughtFurniture = new List<string>();
  11.  
  12. decimal spendMoney = 0;
  13. while (true)
  14. {
  15. string input = Console.ReadLine();
  16. if (input == "Purchase")
  17. { break; }
  18. Regex regex = new Regex(@">>(\w+)<<(\d+\.?\d*)!(\d+)");
  19. MatchCollection current = regex.Matches(input);
  20.  
  21. foreach (Match m in current)
  22. {
  23. string name = m.Groups[1].Value;
  24. decimal price = decimal.Parse(m.Groups[2].Value);
  25. int count = int.Parse(m.Groups[3].Value);
  26. spendMoney += price * count;
  27. boughtFurniture.Add(name);
  28. }
  29.  
  30.  
  31. }if (boughtFurniture.Count > 0)
  32. {
  33. Console.WriteLine("Bought furniture:");
  34. foreach (var item in boughtFurniture)
  35. {
  36. Console.WriteLine(item);
  37. }
  38. }
  39. Console.WriteLine($"Total money spend: {spendMoney:f2}");
  40.  
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement