miroslavbstoyanov

Untitled

Oct 24th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 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. namespace _04.Palindromes
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] text = Console.ReadLine().Split(new char[] { ' ', '.', ',', '?', '!' } , StringSplitOptions.RemoveEmptyEntries);
  14. List<String> listOfPalindromes = new List<String>();
  15.  
  16. for (int i = 0; i < text.Length; i++)
  17. {
  18. bool isTrueOrFalse = IsPalindrome(text[i]);
  19. if (isTrueOrFalse)
  20. {
  21. listOfPalindromes.Add(text[i]);
  22. }
  23. }
  24.  
  25. listOfPalindromes = listOfPalindromes.OrderBy(x => x).ToList();
  26. Console.WriteLine(string.Join(", ", listOfPalindromes));
  27.  
  28. }
  29.  
  30. private static bool IsPalindrome(string word)
  31. {
  32. string reversed = new string(word.Reverse().ToArray());
  33. if (reversed == word)
  34. {
  35. return true;
  36. }
  37. else
  38. {
  39. return false;
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment