Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Problem_3___Raincast
- {
- public class Program
- {
- public static void Main()
- {
- var forecast = new List<string>();
- while (true)
- {
- var input = Console.ReadLine();
- if (input == "Davai Emo")
- {
- break;
- }
- if (input.StartsWith("Type: ") && input.EndsWith("Normal") || input.EndsWith("Danger") || input.EndsWith("Warning"))
- {
- if (forecast.Count == 1)
- {
- continue;
- }
- var type = $"({input.Substring(6)})";
- forecast.Clear();
- forecast.Add(type);
- }
- else if (input.StartsWith("Source: ") && IsSourceValid(input.Substring(8)))
- {
- if (forecast.Count == 1)
- {
- forecast.Add(input.Substring(8));
- }
- }
- else if (input.StartsWith("Forecast: ") && IsForecastValid(input.Substring(10)))
- {
- if (forecast.Count == 2)
- {
- forecast.Insert(1, input.Substring(10) + " ~");
- Console.WriteLine(string.Join(" ", forecast));
- }
- }
- }
- }
- public static bool IsSourceValid (string source)
- {
- var pattern = new Regex(@"[A-Za-z0-9]");
- var match = pattern.Match(source);
- if (match.Success)
- {
- return true;
- }
- return false;
- }
- public static bool IsForecastValid(string forecast)
- {
- var pattern = new Regex(@"\?|\.|!|,");
- var match = pattern.Match(forecast);
- if (match.Success)
- {
- return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement