Advertisement
tsekotsolov

Raincast

Dec 15th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace P03_RainCast
  6. {
  7.     class P03_RainCast
  8.  
  9.     {
  10.  
  11.         static void Main()
  12.         {
  13.             var input = Console.ReadLine();
  14.  
  15.  
  16.             var typePattern = @"(^Type:\s)(Normal|Danger|Warning)$";
  17.             var sourcePattern = @"(^Source:\s)([A-Za-z0-9]+$)";
  18.             var foreCastPattern = @"(^Forecast:\s)([^\.?,!\n]+$)";
  19.  
  20.             var type = string.Empty;
  21.             var forecast = string.Empty;
  22.             string source = string.Empty;
  23.  
  24.             var listType = new List<string>();
  25.             var listForecast = new List<string>();
  26.             var sourceList = new List<string>();
  27.  
  28.  
  29.             while (input != "Davai Emo")
  30.             {
  31.                 if (Regex.IsMatch(input, typePattern) && type == string.Empty)
  32.                 {
  33.                     Regex regex = new Regex(typePattern);
  34.                     Match match = regex.Match(input);
  35.  
  36.                     type = match.Groups[2].ToString();
  37.                 }
  38.  
  39.  
  40.                 else if (Regex.IsMatch(input, sourcePattern))
  41.                 {
  42.                     if (type != string.Empty && source==string.Empty)
  43.                     {
  44.                         Regex regex = new Regex(sourcePattern);
  45.                         Match match = regex.Match(input);
  46.  
  47.                         source = match.Groups[2].ToString();
  48.                     }
  49.                 }
  50.  
  51.                 else if (Regex.IsMatch(input, foreCastPattern))
  52.                 {
  53.                     if (type != string.Empty && source != string.Empty)
  54.                     {
  55.                         Regex regex = new Regex(foreCastPattern);
  56.                         Match match = regex.Match(input);
  57.  
  58.                         forecast = match.Groups[2].ToString();
  59.                     }
  60.                 }
  61.  
  62.                 if (type != string.Empty && forecast != string.Empty && source != string.Empty)
  63.                 {
  64.                     listType.Add(type);
  65.                     listForecast.Add(forecast);
  66.                     sourceList.Add(source);
  67.  
  68.  
  69.                     type = string.Empty;
  70.                     forecast = string.Empty;
  71.                     source = string.Empty;
  72.  
  73.                 }
  74.  
  75.                 input = Console.ReadLine();
  76.             }
  77.  
  78.  
  79.             for (int i = 0; i < listType.Count; i++)
  80.             {
  81.                 Console.WriteLine($"({listType[i]}) {listForecast[i]} ~ {sourceList[i]}");
  82.             }
  83.  
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement