Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace Task_3_RegexMon
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.             string bojomon = @"([a-zA-Z]+)(-+)([a-zA-Z]+)";
  16.             string didimon = @"[^-a-zA-Z]+";
  17.  
  18.             MatchCollection bojoMatch = Regex.Matches(input, bojomon);
  19.             MatchCollection didiMatch = Regex.Matches(input, didimon);
  20.  
  21.             List<Match> list = new List<Match>();
  22.  
  23.             int counter = Math.Min(bojoMatch.Count, didiMatch.Count);
  24.            
  25.                 for (int c = 0; c< counter; c++)
  26.                 {
  27.                     list.Add(didiMatch[c]);
  28.                     list.Add(bojoMatch[c]);
  29.                 }
  30.  
  31.             if (bojoMatch.Count>didiMatch.Count)
  32.             {
  33.                 list.Add(bojoMatch[bojoMatch.Count-1]);
  34.             }
  35.             else if (bojoMatch.Count < didiMatch.Count)
  36.             {
  37.                 list.Add(didiMatch[didiMatch.Count - 1]);
  38.             }
  39.  
  40.             foreach (Match element in list)
  41.             {
  42.                 Console.WriteLine(element);
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement