Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Runtime.InteropServices;
- namespace _02._Boss_Rush
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Regex regex = new Regex(@"([@|#])(?<word1>[a-zA-Z]{3,})\1\1(?<word2>[a-zA-Z]{3,})\1");
- MatchCollection match = regex.Matches(input);
- List<string> matches = new List<string>();
- int count = 0;
- foreach (Match item in match)
- {
- if (item.Success)
- {
- string firstWord = item.Groups["word1"].Value;
- string secondWord = item.Groups["word2"].Value;
- char[] reversed = secondWord.Reverse().ToArray();
- string newWord = new string(reversed);
- if (newWord == firstWord)
- {
- matches.Add($"{firstWord} <=> {secondWord}");
- }
- count++;
- }
- }
- if(match.Count == 0)
- {
- Console.WriteLine("No word pairs found!");
- }
- else
- {
- Console.WriteLine($"{count} word pairs found!");
- }
- if (matches.Count == 0)
- {
- Console.WriteLine("No mirror words!");
- }
- else
- {
- Console.WriteLine("The mirror words are:");
- Console.WriteLine(string.Join(", ", matches));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement