Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Linq;
- namespace AdAstra
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- var dictItemDate = new Dictionary<string, string>();
- var dictItemCalories = new Dictionary<string, int>();
- Regex regexForInput = new Regex(@"(#|\|)(?<item>[a-zA-Z\s]+)(\1)(?<date>[\d]{2}\/[\d]{2}\/[\d]{2})(\1)(?<calories>\d{1,5})(\1)");
- MatchCollection matchesItemDateCalories = regexForInput.Matches(input);
- int sumCalories = 0;
- foreach (Match product in matchesItemDateCalories)
- {
- int calories = int.Parse(product.Groups["calories"].Value);
- sumCalories += calories;
- }
- int days = sumCalories / 2000;
- Console.WriteLine($"You have food to last you for: {days} days!");
- foreach (Match product in matchesItemDateCalories)
- {
- string item = product.Groups["item"].Value;
- string date = product.Groups["date"].Value;
- int calories = int.Parse(product.Groups["calories"].Value);
- Console.WriteLine($"Item: {item}, Best before: {date}, Nutrition: {calories}");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment