Advertisement
Guest User

Untitled

a guest
Sep 1st, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Regexmon
  6. {
  7.     public static void Main()
  8.     {
  9.         string input = Console.ReadLine();
  10.         string bojoPattern = @"[a-zA-Z]+-[a-zA-Z]+";
  11.         string didiPattern = @"[^a-zA-Z-]+";
  12.         StringBuilder sb = new StringBuilder();
  13.         sb.Append(input);
  14.         Regex regexBojo = new Regex(bojoPattern);
  15.         Regex regexDidi = new Regex(didiPattern);
  16.         int count = 1;
  17.  
  18.         while (sb.Length > 0)
  19.         {
  20.             bool isFound = false;
  21.             if (count % 2 != 0)
  22.             {
  23.                 isFound = regexDidi.IsMatch(sb.ToString());
  24.             }
  25.             else
  26.             {
  27.                 isFound = regexBojo.IsMatch(sb.ToString());
  28.                
  29.             }
  30.  
  31.             if (isFound)
  32.             {
  33.                 if (count % 2 != 0)
  34.                 {
  35.                     Match match = regexDidi.Match(sb.ToString());
  36.                     Console.WriteLine(match.Groups[0]);
  37.                     int index = sb.ToString().IndexOf(match.Groups[0].ToString(), 0);
  38.                     sb.Remove(0, match.Groups[0].ToString().Length + index);
  39.                 }
  40.                 else
  41.                 {
  42.                     Match match = regexBojo.Match(sb.ToString());
  43.                     Console.WriteLine(match.Groups[0]);
  44.                     int index = sb.ToString().IndexOf(match.Groups[0].ToString(), 0);
  45.                     sb.Remove(0, match.Groups[0].ToString().Length + index);
  46.                 }
  47.             }
  48.             else
  49.             {
  50.                 return;
  51.             }
  52.  
  53.             count++;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement