angelneychev

Untitled

Apr 10th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.01 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.             int timeDishes = 0;
  17.             int timeCleaning = 0;
  18.             int timeLaundry = 0;
  19.             while (input != "wife is happy")
  20.             {
  21.                 string pattern = @"\<(?<dishes>([a-z0-9]*))\>|\[(?<cleaning>([A-Z0-9]*))\]|\{(?<laundry>([[:punct:][a-zA-Z0-9]*))\}";
  22.                 var match = Regex.Match(input, pattern);
  23.                
  24.                 if (match.Success)
  25.                 {
  26.                     string dishes = match.Groups["dishes"].Value;
  27.                     string cleaning = match.Groups["cleaning"].Value;
  28.                     string caundry = match.Groups["laundry"].Value;
  29.                     if (dishes != string.Empty)
  30.                     {
  31.                       //  string dishes = match.Groups["dishes"].Value;
  32.                         foreach (var dish in dishes)
  33.                         {
  34.                             if (char.IsDigit(dish))
  35.                             {
  36.                                 int a = int.Parse(dish.ToString());
  37.  
  38.                                 timeDishes += a;
  39.                             }
  40.                         }
  41.                     }
  42.                     else if (cleaning != string.Empty)
  43.                     {
  44.                       //  string cleaning = match.Groups["cleaning"].Value;
  45.                         foreach (var clean in cleaning)
  46.                         {
  47.                             if (char.IsDigit(clean))
  48.                             {
  49.                                 int a = int.Parse(clean.ToString());
  50.  
  51.                                 timeCleaning += a;
  52.                             }
  53.                         }
  54.                     }
  55.                     else if (caundry != string.Empty)
  56.                     {
  57.                        // string caundry = match.Groups["laundry"].Value;
  58.                         foreach (var caund in caundry)
  59.                         {
  60.                             if (char.IsDigit(caund))
  61.                             {
  62.                                 int a = int.Parse(caund.ToString());
  63.  
  64.                                 timeLaundry += a;
  65.                             }
  66.                         }
  67.                     }
  68.                 }
  69.                 input = Console.ReadLine();
  70.             }
  71.  
  72.             int totalMinutes = timeLaundry + timeCleaning + timeDishes;
  73.  
  74.             Console.WriteLine($"Doing the dishes - {timeDishes} min.");
  75.             Console.WriteLine($"Cleaning the house - {timeCleaning} min.");
  76.             Console.WriteLine($"Doing the laundry - {timeLaundry} min.");
  77.             Console.WriteLine($"Total - {totalMinutes} min.");
  78.         }
  79.     }
  80. }
Add Comment
Please, Sign In to add comment