Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. class Raincast
  10. {
  11.     static void Main(string[] args)
  12.     {
  13.         var typeFound = false;
  14.         var sourceFound = false;
  15.         var forecastFound = false;
  16.  
  17.         var type = string.Empty;
  18.         var source = string.Empty;
  19.         var forecast = string.Empty;
  20.  
  21.         while (true)
  22.         {
  23.             string inputLine = Console.ReadLine();
  24.  
  25.             if (inputLine == "Davai Emo")
  26.                 break;
  27.             RegexOptions options = RegexOptions.Multiline;
  28.             string pattern1 = @"^(Type: )(Normal|Warning|Danger)$";
  29.             var matches1 = Regex.Matches(inputLine, pattern1, options);
  30.             string pattern2 = @"^(Source: )(\w+)$";
  31.             var matches2 = Regex.Matches(inputLine, pattern2, options);
  32.             string pattern3 = @"^(Forecast: )([^.,!?\n]*)$";
  33.             var matches3 = Regex.Matches(inputLine, pattern3, options);
  34.  
  35.             if (!typeFound && matches1.Count > 0)
  36.                 foreach (Match m in matches1)
  37.                 {
  38.                     type = m.Groups[2].Value;
  39.                     typeFound = true;
  40.                 }
  41.             if (!sourceFound && typeFound && matches2.Count > 0)
  42.                 foreach (Match m in matches2)
  43.                 {
  44.                     source = m.Groups[2].Value;
  45.                     sourceFound = true;
  46.                 }
  47.             if (!forecastFound && sourceFound && matches3.Count > 0)
  48.                 foreach (Match m in matches3)
  49.                 {
  50.                     forecast = m.Groups[2].Value;
  51.                     forecastFound = true;
  52.                 }
  53.             if (typeFound && sourceFound && forecastFound)
  54.             {
  55.                 Console.WriteLine($"({type}) {forecast} ~ {source}");
  56.                 typeFound = false;
  57.                 sourceFound = false;
  58.                 forecastFound = false;
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement