Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace _02.Ad_Astra
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- string regex = @"([#|])(?<food>[a-zA-Z\s]+)(\1)(?<date>[0-9]{2}\/[0-9]{2}\/[0-9]{2})(\1)(?<calories>[0-9]+)(\1)";
- MatchCollection matches = Regex.Matches(input, regex);
- int totalCalories = 0;
- int neededCalsFor1Day = 2000;
- foreach (Match match in matches)
- {
- totalCalories += int.Parse(match.Groups["calories"].Value);
- }
- int daysToLast = totalCalories / neededCalsFor1Day;
- Console.WriteLine($"You have food to last you for: {daysToLast} days!");
- foreach (Match match in matches)
- {
- Console.WriteLine($"Item: {match.Groups["food"].Value}, Best before: {match.Groups["date"].Value}, Nutrition: {match.Groups["calories"].Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement