Advertisement
social1986

Untitled

Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace Problem_3___Raincast
  6. {
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. var forecast = new List<string>();
  12.  
  13. while (true)
  14. {
  15. var input = Console.ReadLine();
  16.  
  17. if (input == "Davai Emo")
  18. {
  19. break;
  20. }
  21.  
  22. if (input.StartsWith("Type: ") && input.EndsWith("Normal") || input.EndsWith("Danger") || input.EndsWith("Warning"))
  23. {
  24. if (forecast.Count == 1)
  25. {
  26. continue;
  27. }
  28. var type = $"({input.Substring(6)})";
  29. forecast.Clear();
  30. forecast.Add(type);
  31. }
  32. else if (input.StartsWith("Source: ") && IsSourceValid(input.Substring(8)))
  33. {
  34. if (forecast.Count == 1)
  35. {
  36. forecast.Add(input.Substring(8));
  37. }
  38. }
  39. else if (input.StartsWith("Forecast: ") && IsForecastValid(input.Substring(10)))
  40. {
  41. if (forecast.Count == 2)
  42. {
  43. forecast.Insert(1, input.Substring(10) + " ~");
  44. Console.WriteLine(string.Join(" ", forecast));
  45. }
  46. }
  47. }
  48. }
  49.  
  50. public static bool IsSourceValid (string source)
  51. {
  52. var pattern = new Regex(@"[A-Za-z0-9]");
  53.  
  54. var match = pattern.Match(source);
  55. if (match.Success)
  56. {
  57. return true;
  58. }
  59. return false;
  60. }
  61.  
  62. public static bool IsForecastValid(string forecast)
  63. {
  64. var pattern = new Regex(@"\?|\.|!|,");
  65.  
  66. var match = pattern.Match(forecast);
  67.  
  68. if (match.Success)
  69. {
  70. return false;
  71. }
  72. return true;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement