Advertisement
silvana1303

mirror words

Aug 5th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace _02._Boss_Rush
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             Regex regex = new Regex(@"([@|#])(?<word1>[a-zA-Z]{3,})\1\1(?<word2>[a-zA-Z]{3,})\1");
  15.  
  16.             MatchCollection match = regex.Matches(input);
  17.  
  18.             List<string> matches = new List<string>();
  19.  
  20.             int count = 0;
  21.  
  22.             foreach (Match item in match)
  23.             {
  24.                 if (item.Success)
  25.                 {
  26.                     string firstWord = item.Groups["word1"].Value;
  27.                     string secondWord = item.Groups["word2"].Value;
  28.  
  29.                     char[] reversed = secondWord.Reverse().ToArray();
  30.                     string newWord = new string(reversed);
  31.  
  32.                     if (newWord == firstWord)
  33.                     {
  34.                         matches.Add($"{firstWord} <=> {secondWord}");
  35.                        
  36.                     }
  37.                     count++;
  38.                 }
  39.                
  40.             }
  41.  
  42.             if(match.Count == 0)
  43.             {
  44.                 Console.WriteLine("No word pairs found!");
  45.             }
  46.             else
  47.             {
  48.                 Console.WriteLine($"{count} word pairs found!");
  49.             }
  50.             if (matches.Count == 0)
  51.             {
  52.                 Console.WriteLine("No mirror words!");
  53.             }
  54.             else
  55.             {
  56.                 Console.WriteLine("The mirror words are:");
  57.                 Console.WriteLine(string.Join(", ", matches));
  58.             }
  59.  
  60.            
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement