Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class Person
- {
- public string Name {get;set;}
- public string Product {get;set;}
- public double TotalPrice {get;set;}
- }
- public class Program
- {
- public static void Main()
- {
- string namePattern = @"%(?<name>[A-Z][a-z]+)%";
- string productPattern = @"<(?<product>\w+)>";
- string quantityPattern = @"\|(?<quantity>\d+)\|";
- string pricePattern = @"(?<price>\d+(\.\d+)?)\$";
- double totalIncome =0;
- List<Person> personsData = new List<Person>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end of shift")
- {
- break;
- }
- string name = string.Empty;
- string product = string.Empty;
- int quantity =0;
- double price =0;
- if (Regex.IsMatch(input,namePattern))
- {
- Match matchedName = Regex.Match(input,namePattern);
- name = matchedName.Groups["name"].Value;
- }
- if (name == string.Empty)
- {
- continue;
- }
- if (Regex.IsMatch(input,productPattern))
- {
- Match matchedProduct = Regex.Match(input,productPattern);
- product = matchedProduct.Groups["product"].Value;
- }
- if (product == string.Empty)
- {
- continue;
- }
- if (Regex.IsMatch(input,quantityPattern))
- {
- Match matchedQuantity = Regex.Match(input,quantityPattern);
- quantity =int.Parse(matchedQuantity.Groups["quantity"].Value);
- }
- if (quantity==0)
- {
- continue;
- }
- if (Regex.IsMatch(input,pricePattern))
- {
- Match matchedPrice = Regex.Match(input,pricePattern);
- price = double.Parse(matchedPrice.Groups["price"].Value);
- }
- if (price==0)
- {
- continue;
- }
- double totalPrice = price * quantity;
- personsData.Add(new Person
- {
- Name=name,
- Product=product,
- TotalPrice = totalPrice
- });
- }
- foreach (var person in personsData)
- {
- Console.WriteLine("{0}: {1} - {2:f2}",person.Name,person.Product,person.TotalPrice);
- totalIncome += person.TotalPrice;
- }
- Console.WriteLine("Total income: {0:f2}",totalIncome);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement