Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- char[] delimeters = new char[] { ' ', ',', '.', '?', '!' };
- string[] textInput = Console.ReadLine().Split(delimeters, StringSplitOptions.RemoveEmptyEntries);
- List<string> palindromes = new List<string>();
- for (int i = 0; i < textInput.Length; i++)
- {
- string firstPart = textInput[i].Substring((textInput[i].Length + 1) / 2);
- char[] getReversed = firstPart.ToCharArray();
- Array.Reverse(getReversed);
- firstPart = new string(getReversed);
- string secondPart = textInput[i].Substring(0, textInput[i].Length / 2);
- if (firstPart == secondPart)
- {
- palindromes.Add(textInput[i]);
- }
- }
- palindromes.Distinct();
- palindromes.Sort();
- Console.WriteLine(string.Join(", ", palindromes));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement