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;
- namespace AdAstra
- {
- class Program
- {
- static void Main(string[] args)
- {
- Regex regex = new Regex(@"([|#])(?<name>[A-Za-z\s]+)\1(?<date>\d{2}\/\d{2}\/\d{2})\1(?<calories>\d{1,5})\1");
- MatchCollection matches = regex.Matches(Console.ReadLine());
- List<Dictionary<string, string>> products = new List<Dictionary<string, string>>();
- int sumCalories = 0;
- foreach (Match match in matches)
- {
- GroupCollection m = regex.Match(match.ToString()).Groups;
- products.Add(new Dictionary<string, string>()
- {
- { "name", m["name"].ToString() },
- { "date", m["date"].ToString() },
- { "calories", m["calories"].ToString() }
- });
- sumCalories += int.Parse(m["calories"].ToString());
- }
- Console.WriteLine($"You have food to last you for: {sumCalories / 2000} days!");
- foreach (var p in products) {
- Console.WriteLine($"Item: {p["name"]}, Best before: {p["date"]}, Nutrition: {p["calories"]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement