Advertisement
YavorJS

Palindromes 100%

Aug 8th, 2016
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 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 _7.Palindromes
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. char[] delimiters = new char[] { ' ', ',', '?', '!', '.', ':' };
  14. string[] text = Console.ReadLine().Split(delimiters, StringSplitOptions.RemoveEmptyEntries).ToArray();
  15. string wordToCheck = "";
  16. List<string> palindromes = new List<string>();
  17. for (int word = 0; word < text.Length; word++)
  18. {
  19. wordToCheck = text[word];
  20. bool palindrome = true;
  21. if (wordToCheck.Length == 1)
  22. {
  23. palindromes.Add(wordToCheck);
  24. }
  25. for (int pal = 0; pal < wordToCheck.Length / 2; pal++)
  26. {
  27. if (wordToCheck[pal] != wordToCheck[wordToCheck.Length - pal-1])
  28. {
  29. palindrome = false;
  30. }
  31. } //end of for
  32. if (palindrome)
  33. {
  34. palindromes.Add(wordToCheck);
  35. }
  36. }//end of for
  37. palindromes = palindromes.Distinct().ToList();
  38. palindromes.Sort();
  39. Console.WriteLine(string.Join(", ", palindromes));
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement