Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace p_03
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int totalSum = 0;
  11.             int dishes = 0;
  12.             int cleaning = 0;
  13.             int laundry = 0;
  14.  
  15.             while (true)
  16.             {
  17.                 string commands = Console.ReadLine();
  18.                 if (commands == "wife is happy")
  19.                 {
  20.                     Console.WriteLine($"Doing the dishes - {dishes} min.");
  21.                     Console.WriteLine($"Cleaning the house - {cleaning} min.");
  22.                     Console.WriteLine($"Doing the laundry - {laundry} min.");
  23.                     Console.WriteLine($"Total - {totalSum} min.");
  24.                     break;
  25.                 }
  26.  
  27.                 int currentDishes = 0;
  28.                 int currentCleaning = 0;
  29.                 int currentLaundry = 0;
  30.                 string currentText = "";
  31.                 bool isValid = false;
  32.  
  33.                 string patternForDishes = @"(?<=\<)([a-z0-9]+)(?=\>)";
  34.                 MatchCollection regexForDishes = Regex.Matches(commands, patternForDishes);
  35.                 foreach (Match match in regexForDishes)
  36.                 {
  37.                     currentText = match.ToString();
  38.                     for (int i = 0; i < currentText.Length; i++)
  39.                     {
  40.                         if (char.IsDigit(currentText[i]))
  41.                         {
  42.                             currentDishes += int.Parse(currentText[i].ToString());
  43.                         }
  44.                     }
  45.  
  46.                     isValid = true;
  47.                     dishes += currentDishes;
  48.                     totalSum += currentDishes;
  49.                 }
  50.  
  51.                 if (isValid)
  52.                 {
  53.                     continue;
  54.                 }
  55.  
  56.                 string patternForCleaning = @"(?<=\[)([A-Z0-9]+)(?=\])";
  57.                 MatchCollection regexForCleaning = Regex.Matches(commands, patternForCleaning);
  58.                 foreach (Match match in regexForCleaning)
  59.                 {
  60.                     currentText = match.ToString();
  61.                     for (int i = 0; i < currentText.Length; i++)
  62.                     {
  63.                         if (char.IsDigit(currentText[i]))
  64.                         {
  65.                             currentCleaning += int.Parse(currentText[i].ToString());
  66.                         }
  67.                     }
  68.  
  69.                     isValid = true;
  70.                     cleaning += currentCleaning;
  71.                     totalSum += currentCleaning;
  72.                 }
  73.  
  74.                 if (isValid)
  75.                 {
  76.                     continue;
  77.                 }
  78.  
  79.                 string patternForLaundry = @"(?<=\{)(.+)(?=\})";
  80.                 MatchCollection regexForLaundry = Regex.Matches(commands, patternForLaundry);
  81.                 foreach (Match match in regexForLaundry)
  82.                 {
  83.                     currentText = match.ToString();
  84.                     for (int i = 0; i < currentText.Length; i++)
  85.                     {
  86.                         if (char.IsDigit(currentText[i]))
  87.                         {
  88.                             currentLaundry += int.Parse(currentText[i].ToString());
  89.                         }
  90.                     }
  91.  
  92.                     laundry += currentLaundry;
  93.                     totalSum += currentLaundry;
  94.                 }
  95.             }
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement