Advertisement
dbunalov

Palindromes

Oct 19th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Palindromes
  6. {
  7.     class Palindromes
  8.     {
  9.         static void Main()
  10.         {
  11.             string[] input = Console.ReadLine().Split(new char[] { ' ', '.', ',', '!', '?' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  12.  
  13.             List<string> palindrom = new List<string>();
  14.             for (int i = 0; i < input.Length; i++)
  15.             {
  16.                 char[] word = input[i].ToCharArray();
  17.                 Array.Reverse(word);
  18.                 string tempWord = new string(word);
  19.                 if (input[i].Equals(tempWord))
  20.                 {
  21.                     palindrom.Add(tempWord);
  22.                 }
  23.             }
  24.             List<string> result = new List<string>(palindrom.OrderBy(ord => ord).Distinct());
  25.             Console.WriteLine(string.Join(", ", result));
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement