Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class Program
- {
- static void Main(string[] args)
- {
- string[] words = Console.ReadLine().Split(new char[] {',',' ','?','!','.' },StringSplitOptions.RemoveEmptyEntries).ToArray();
- List<string> palindromes = new List<string>();
- for (int word = 0; word < words.Length; word++)
- {
- string myString = words[word];
- bool palindrome = getStatus(myString);
- if (palindrome)
- {
- palindromes.Add(myString);
- }
- }
- palindromes = palindromes.Distinct().OrderBy(x=>x).ToList();
- Console.WriteLine(string.Join(", ",palindromes));
- }
- public static bool getStatus(string myString)
- {
- string first = myString.Substring(0, myString.Length / 2);
- char[] arr = myString.ToCharArray();
- Array.Reverse(arr);
- string temp = new string(arr);
- string second = temp.Substring(0, temp.Length / 2);
- return first.Equals(second);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement