Advertisement
Guest User

Untitled

a guest
Oct 18th, 2016
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         char[] delimeters = new char[] { ' ', ',', '.', '?', '!' };
  10.         string[] textInput = Console.ReadLine().Split(delimeters, StringSplitOptions.RemoveEmptyEntries);
  11.  
  12.         List<string> palindromes = new List<string>();
  13.  
  14.         for (int i = 0; i < textInput.Length; i++)
  15.         {
  16.             string firstPart = textInput[i].Substring((textInput[i].Length + 1) / 2);
  17.             char[] getReversed = firstPart.ToCharArray();
  18.             Array.Reverse(getReversed);  
  19.             firstPart = new string(getReversed);
  20.             string secondPart = textInput[i].Substring(0, textInput[i].Length / 2);
  21.             if (firstPart == secondPart)
  22.             {
  23.                 palindromes.Add(textInput[i]);
  24.             }
  25.         }
  26.         palindromes.Distinct();
  27.         palindromes.Sort();
  28.  
  29.         Console.WriteLine(string.Join(", ", palindromes));
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement