Advertisement
parunowaa

02.Ad_Astra

Dec 11th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _02.Ad_Astra
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.             string regex = @"([#|])(?<food>[a-zA-Z\s]+)(\1)(?<date>[0-9]{2}\/[0-9]{2}\/[0-9]{2})(\1)(?<calories>[0-9]+)(\1)";
  12.            
  13.             MatchCollection matches = Regex.Matches(input, regex);
  14.            
  15.             int totalCalories = 0;
  16.             int neededCalsFor1Day = 2000;
  17.             foreach (Match match in matches)
  18.             {
  19.                 totalCalories += int.Parse(match.Groups["calories"].Value);
  20.             }
  21.            
  22.             int daysToLast = totalCalories / neededCalsFor1Day;
  23.             Console.WriteLine($"You have food to last you for: {daysToLast} days!");
  24.  
  25.             foreach (Match match in matches)
  26.             {
  27.                 Console.WriteLine($"Item: {match.Groups["food"].Value}, Best before: {match.Groups["date"].Value}, Nutrition: {match.Groups["calories"].Value}");
  28.             }
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement