Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Palindromes
- {
- class Palindromes
- {
- static void Main()
- {
- string[] input = Console.ReadLine().Split(new char[] { ' ', '.', ',', '!', '?' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- List<string> palindrom = new List<string>();
- for (int i = 0; i < input.Length; i++)
- {
- char[] word = input[i].ToCharArray();
- Array.Reverse(word);
- string tempWord = new string(word);
- if (input[i].Equals(tempWord))
- {
- palindrom.Add(tempWord);
- }
- }
- List<string> result = new List<string>(palindrom.OrderBy(ord => ord).Distinct());
- Console.WriteLine(string.Join(", ", result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement