Advertisement
angelneychev

Untitled

Apr 10th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace _03._Santa_s_Secret_Helper
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.           //  int key = int.Parse(Console.ReadLine());
  14.             string input = Console.ReadLine();
  15.             StringBuilder sb = new StringBuilder();
  16.             string pattern = @"(\<(?<dishes>([a-z0-9]*))\>)|(\[(?<cleaning>([A-Z0-9]*))\])|(\{(?<laundry>([[:punct:]][:alnum:]]*))\})";
  17.             int timeDishes = 0;
  18.             int timeCleaning = 0;
  19.             int timeLaundry = 0;
  20.             while (input != "wife is happy")
  21.             {
  22.                
  23.                 var match = Regex.Match(input, pattern);
  24.                
  25.                 if (match.Success)
  26.                 {
  27.                     string dishes = match.Groups["dishes"].Value;
  28.                     string cleaning = match.Groups["cleaning"].Value;
  29.                     string caundry = match.Groups["laundry"].Value;
  30.                     if (dishes != string.Empty)
  31.                     {
  32.                       //  string dishes = match.Groups["dishes"].Value;
  33.                         foreach (var dish in dishes)
  34.                         {
  35.                             if (char.IsDigit(dish))
  36.                             {
  37.                                 int a = int.Parse(dish.ToString());
  38.  
  39.                                 timeDishes += a;
  40.                             }
  41.                         }
  42.                     }
  43.                     else if (cleaning != string.Empty)
  44.                     {
  45.                       //  string cleaning = match.Groups["cleaning"].Value;
  46.                         foreach (var clean in cleaning)
  47.                         {
  48.                             if (char.IsDigit(clean))
  49.                             {
  50.                                 int a = int.Parse(clean.ToString());
  51.  
  52.                                 timeCleaning += a;
  53.                             }
  54.                         }
  55.                     }
  56.                     else if (caundry != string.Empty)
  57.                     {
  58.                        // string caundry = match.Groups["laundry"].Value;
  59.                         foreach (var caun in caundry)
  60.                         {
  61.                             if (char.IsDigit(caun))
  62.                             {
  63.                                 int a = int.Parse(caun.ToString());
  64.  
  65.                                 timeLaundry += a;
  66.                             }
  67.                         }
  68.                     }
  69.                 }
  70.                 input = Console.ReadLine();
  71.             }
  72.  
  73.             int totalMinutes = timeLaundry + timeCleaning + timeDishes;
  74.  
  75.             Console.WriteLine($"Doing the dishes - {timeDishes} min.");
  76.             Console.WriteLine($"Cleaning the house - {timeCleaning} min.");
  77.             Console.WriteLine($"Doing the laundry - {timeLaundry} min.");
  78.             Console.WriteLine($"Total - {totalMinutes} min.");
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement