Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- using System.Text.RegularExpressions;
- namespace ProblemThreeExam
- {
- class Program
- {
- static void Main(string[] args)
- {
- string income = Console.ReadLine();
- string patern= @"%([A-Z][a-z]+)%[^(|$%.)]*<(\w+)>[^(|$%.)]*\|([0-9]+)\|[^(|$%.0-9)]*([0-9]+.?[0-9]*)\$";
- List<string> arr= new List<string>();
- Regex reg = new Regex(patern);
- double total = 0;
- while (income!="end of shift")
- {
- Match m = reg.Match(income);
- if (m.Success)
- {
- string name = m.Groups[1].Value.Trim('%');
- string product = m.Groups[2].Value.Trim('>');
- int quantity = int.Parse(m.Groups[3].Value.Trim('|'));
- double price = double.Parse(m.Groups[4].Value.Trim('$'));
- double sum = (quantity * price);
- total += sum;
- string toAdd = ($"{name}: {product} - {sum:f2}");
- arr.Add(toAdd);
- }
- income = Console.ReadLine();
- }
- foreach (var item in arr)
- {
- Console.WriteLine(string.Join(" ",item));
- }
- Console.WriteLine($"Total income: {total:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement