Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. string type = @"^Type: (Normal|Warning|Danger)$";
  9. string source = @"^Source: ([A-Za-z0-9]+)$";
  10. string forecast = @"^Forecast: ([^!.,?]+)$";
  11.  
  12. string[] output = new string[3];
  13.  
  14. bool haveType = false;
  15. bool haveSource = false;
  16.  
  17. var input = Console.ReadLine();
  18. while (input != "Davai Emo")
  19. {
  20. var isType = Regex.IsMatch(input, type);
  21. var isSource = Regex.IsMatch(input, source);
  22. var isForecast = Regex.IsMatch(input, forecast);
  23.  
  24. if (isType && !haveType)
  25. {
  26. foreach (Match m in Regex.Matches(input, type))
  27. {
  28. output[0] = m.Groups[1].Value;
  29. }
  30.  
  31. haveType = true;
  32. }
  33. else if (isSource && haveType && !haveSource)
  34. {
  35. foreach (Match m in Regex.Matches(input, source))
  36. {
  37. output[1] = m.Groups[1].Value;
  38. }
  39.  
  40. haveSource = true;
  41. }
  42. else if (isForecast && haveSource)
  43. {
  44. foreach (Match m in Regex.Matches(input, forecast))
  45. {
  46. output[2] = m.Groups[1].Value;
  47. }
  48.  
  49. Console.WriteLine("({0}) {1} ~ {2}", output[0], output[2], output[1]);
  50. haveType = false;
  51. haveSource = false;
  52. }
  53. input = Console.ReadLine();
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement