Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main()
- {
- string type = @"^Type: (Normal|Warning|Danger)$";
- string source = @"^Source: ([A-Za-z0-9]+)$";
- string forecast = @"^Forecast: ([^!.,?]+)$";
- string[] output = new string[3];
- bool haveType = false;
- bool haveSource = false;
- var input = Console.ReadLine();
- while (input != "Davai Emo")
- {
- var isType = Regex.IsMatch(input, type);
- var isSource = Regex.IsMatch(input, source);
- var isForecast = Regex.IsMatch(input, forecast);
- if (isType && !haveType)
- {
- foreach (Match m in Regex.Matches(input, type))
- {
- output[0] = m.Groups[1].Value;
- }
- haveType = true;
- }
- else if (isSource && haveType && !haveSource)
- {
- foreach (Match m in Regex.Matches(input, source))
- {
- output[1] = m.Groups[1].Value;
- }
- haveSource = true;
- }
- else if (isForecast && haveSource)
- {
- foreach (Match m in Regex.Matches(input, forecast))
- {
- output[2] = m.Groups[1].Value;
- }
- Console.WriteLine("({0}) {1} ~ {2}", output[0], output[2], output[1]);
- haveType = false;
- haveSource = false;
- }
- input = Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement