emilia98

RegexMon

Aug 16th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _03.RegexMon
  5. {
  6.     class RegexMon
  7.     {
  8.         static void Main()
  9.         {
  10.             string text = Console.ReadLine();
  11.             Regex pattern = new Regex(@"(?<Didi>[^A-Za-z\-]+)|(?<Bojo>[A-Za-z]+[\-]{1}[A-Za-z]+)");
  12.  
  13.             MatchCollection matchesCollection = pattern.Matches(text);
  14.             int turn = 1;
  15.             foreach (Match match in matchesCollection)
  16.             {
  17.                 var didi = match.Groups["Didi"];
  18.                 var bojo = match.Groups["Bojo"];
  19.  
  20.                 if (turn % 2 == 1)
  21.                 {
  22.                     if (didi.Length == 0)
  23.                     {
  24.                         continue;
  25.                     }
  26.                     else
  27.                     {
  28.                         Console.WriteLine(didi);
  29.                         turn++;
  30.                     }
  31.                 }
  32.                 else
  33.                 {
  34.                     if (bojo.Length == 0)
  35.                     {
  36.                         continue;
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.WriteLine(bojo);
  41.                         turn++;
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment