Advertisement
YavorGrancharov

Raincast

Jan 4th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace Raincast
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             string type = @"^(?:Type:\s)(Normal|Warning|Danger)$";
  12.             string source = @"^(?:Source:\s)(\w+)$";
  13.             string forecast = @"^(?:Forecast:\s)([^\.\!\,\?]+)$";
  14.  
  15.             string input = Console.ReadLine();
  16.  
  17.             List<string> raincasts = new List<string>();
  18.  
  19.             string types = "type";
  20.  
  21.             string currentRainCast = string.Empty;
  22.  
  23.             while (input != "Davai Emo")
  24.             {
  25.                 switch (types)
  26.                 {
  27.                     case "type":
  28.                         if (Regex.IsMatch(input, type))
  29.                         {
  30.                             currentRainCast = "(" + Regex.Match(input, type).Groups[1].Value + ")";
  31.                             types = "source";
  32.                         }
  33.                         break;
  34.                     case "source":
  35.                         if (Regex.IsMatch(input, source))
  36.                         {
  37.                             currentRainCast += " " + "***" + " ~ " + Regex.Match(input, source).Groups[1].Value;
  38.                             types = "forecast";
  39.                         }
  40.                         break;
  41.                     case "forecast":
  42.                         if (Regex.IsMatch(input, forecast))
  43.                         {
  44.                             currentRainCast = currentRainCast.Replace("***", Regex.Match(input, forecast).Groups[1].Value);
  45.                             raincasts.Add(currentRainCast);
  46.                             types = "type";
  47.                         }
  48.                         break;
  49.                 }
  50.                 input = Console.ReadLine();
  51.             }
  52.             foreach (var raincast in raincasts)
  53.             {
  54.                 Console.WriteLine(raincast);
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement