Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main(string[] args)
- {
- // input
- string input = Console.ReadLine();
- MatchCollection MatchesWords = Regex.Matches(input, @"\b\w+\b");
- // regex matches to array
- var matches = MatchesWords.Cast<Match>()
- .Select(m => m.Value).OrderBy(m => m);
- // print with foreach
- foreach (var word in matches)
- if (Palindrome(word)) Console.WriteLine(word);
- Console.WriteLine();
- }
- static bool Palindrome(string word)
- {
- return Enumerable.SequenceEqual(word.ToCharArray(), word.ToCharArray().Reverse());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement