Advertisement
Guest User

Palindromes

a guest
Oct 18th, 2016
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string[] words = Console.ReadLine().Split(new char[] {',',' ','?','!','.' },StringSplitOptions.RemoveEmptyEntries).ToArray();
  12. List<string> palindromes = new List<string>();
  13. for (int word = 0; word < words.Length; word++)
  14. {
  15. string myString = words[word];
  16. bool palindrome = getStatus(myString);
  17. if (palindrome)
  18. {
  19. palindromes.Add(myString);
  20. }
  21. }
  22. palindromes = palindromes.Distinct().OrderBy(x=>x).ToList();
  23. Console.WriteLine(string.Join(", ",palindromes));
  24. }
  25.  
  26.  
  27. public static bool getStatus(string myString)
  28. {
  29. string first = myString.Substring(0, myString.Length / 2);
  30. char[] arr = myString.ToCharArray();
  31. Array.Reverse(arr);
  32. string temp = new string(arr);
  33. string second = temp.Substring(0, temp.Length / 2);
  34. return first.Equals(second);
  35. }
  36.  
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement