Advertisement
bullit3189

ChoreWars-FinalExam-StringProblem

Mar 14th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. int dishesTime =0;
  12. int cleaningTime =0;
  13. int laundryTime =0;
  14.  
  15. string dishesPattern = @"<(?<dishes>[a-z0-9]+)>";
  16. string cleaningPattern = @"\[(?<cleaning>[A-Z0-9]+)\]";
  17. string laundryPattern = @"{(?<laundry>.+)}";
  18.  
  19. while (true)
  20. {
  21. string command = Console.ReadLine();
  22.  
  23. if (command == "wife is happy")
  24. {
  25. break;
  26. }
  27.  
  28. if (Regex.IsMatch(command,dishesPattern))
  29. {
  30. Match matchedDishes = Regex.Match(command,dishesPattern);
  31. string dishes = matchedDishes.Groups["dishes"].Value;
  32.  
  33. for (int i=0; i<dishes.Length; i++)
  34. {
  35. char curr = dishes[i];
  36.  
  37. if (char.IsDigit(curr))
  38. {
  39. int time = int.Parse(curr.ToString());
  40. dishesTime+=time;
  41. }
  42. }
  43. }
  44. else if (Regex.IsMatch(command,cleaningPattern))
  45. {
  46. Match matchedCleaning = Regex.Match(command,cleaningPattern);
  47. string cleaning = matchedCleaning.Groups["cleaning"].Value;
  48.  
  49. for (int i=0; i<cleaning.Length; i++)
  50. {
  51. char curr = cleaning[i];
  52.  
  53. if (char.IsDigit(curr))
  54. {
  55. int time = int.Parse(curr.ToString());
  56. cleaningTime += time;
  57. }
  58. }
  59. }
  60. else if (Regex.IsMatch(command,laundryPattern))
  61. {
  62. Match matchedLaundry = Regex.Match(command,laundryPattern);
  63. string laundry = matchedLaundry.Groups["laundry"].Value;
  64.  
  65. for (int i=0; i<laundry.Length; i++)
  66. {
  67. char curr = laundry[i];
  68.  
  69. if (char.IsDigit(curr))
  70. {
  71. int time = int.Parse(curr.ToString());
  72. laundryTime+=time;
  73. }
  74. }
  75. }
  76. }
  77.  
  78. Console.WriteLine("Doing the dishes - {0} min.",dishesTime);
  79. Console.WriteLine("Cleaning the house - {0} min.",cleaningTime);
  80. Console.WriteLine("Doing the laundry - {0} min.",laundryTime);
  81. Console.WriteLine("Total - {0} min.",dishesTime+cleaningTime+laundryTime);
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement