TheBulgarianWolf

Furnitures

Apr 15th, 2021
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace Furniture
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Regex regex = new Regex(@">>(?<name>[A-Za-z]+)<<(?<price>\d+\.?\d*)!(?<quantity>\d+)");
  12.             List<string> furnitures = new List<string>();
  13.             double totalSum = 0;
  14.             while (true)
  15.             {
  16.                 string line = Console.ReadLine();
  17.                 if(line == "Purchase")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 Match match = regex.Match(line);
  23.                 if (!match.Success)
  24.                 {
  25.                     continue;
  26.                 }
  27.  
  28.                 string name = match.Groups["name"].Value;
  29.                 double price = double.Parse(match.Groups["price"].Value);
  30.                 double quantity = int.Parse(match.Groups["quantity"].Value);
  31.                 furnitures.Add(name);
  32.                 totalSum += price * quantity;
  33.             }
  34.  
  35.             Console.WriteLine("Furnitures: ");
  36.             foreach(string f in furnitures)
  37.             {
  38.                 Console.WriteLine(f);
  39.             }
  40.             Console.WriteLine("Total price: {0:F2}", totalSum);
  41.         }
  42.     }
  43. }
  44.  
Add Comment
Please, Sign In to add comment