Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Linq;
- namespace MirrorWord
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- var list = new List<string>();
- Regex regexForWords = new Regex(@"(#|@)(?'first'[a-zA-Z]{3,})\1\1(?'second'[a-zA-Z]{3,})\1");
- MatchCollection matchesForWord = regexForWords.Matches(input);
- if (regexForWords.IsMatch(input))
- {
- foreach (Match match in matchesForWord)
- {
- string firstWord = match.Groups["first"].Value;
- string secondWord = match.Groups["second"].Value;
- char[] reverse= secondWord.Reverse().ToArray(); //char Array
- string reverseSecondWord = string.Join("", reverse);
- if (firstWord == reverseSecondWord)
- {
- string stringForAdd = firstWord + " " + "<=>" + " " + secondWord;
- list.Add(stringForAdd);
- }
- }
- Console.WriteLine($"{matchesForWord.Count} word pairs found!");
- if (list.Count > 0)
- {
- Console.WriteLine("The mirror words are:");
- Console.WriteLine(string.Join(", ",list));
- }
- else
- {
- Console.WriteLine("No mirror words!");
- }
- }
- else
- {
- Console.WriteLine("No word pairs found!");
- Console.WriteLine("No mirror words!");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment