Advertisement
Spocoman

01. Furniture

Apr 18th, 2023 (edited)
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace Furniture
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             var pattern = new Regex(@">>(?<furniture>[A-Za-z]+)<<(?<price>\d+([.]\d+)?)!(?<quantity>\d+)");
  13.  
  14.             Console.WriteLine("Bought furniture:");
  15.  
  16.             double totalSum = 0;
  17.  
  18.             string command;
  19.  
  20.             while ((command = Console.ReadLine()) != "Purchase")
  21.             {
  22.                 if (pattern.IsMatch(command))
  23.                 {
  24.                     var current = pattern.Match(command);
  25.  
  26.                     Console.WriteLine(current.Groups["furniture"].Value);
  27.  
  28.                     totalSum += double.Parse(current.Groups["price"].Value) * int.Parse(current.Groups["quantity"].Value);
  29.                 }
  30.             }
  31.  
  32.             Console.WriteLine($"Total money spend: {totalSum:f2}");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement