Advertisement
Guest User

Palindromes

a guest
Aug 8th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 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. if (wordToCheck.Length == 1)
  21. {
  22. palindromes.Add(wordToCheck);
  23. }
  24. for (int pal = 0; pal < wordToCheck.Length / 2; pal++)
  25. {
  26. if (wordToCheck[pal] == wordToCheck[wordToCheck.Length - 1])
  27. {
  28. palindromes.Add(wordToCheck);
  29. }
  30. } //end of for
  31. }//end of for
  32. palindromes = palindromes.Distinct().ToList();
  33. palindromes.Sort();
  34. Console.WriteLine(string.Join(", ", palindromes));
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement