Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5.  
  6. namespace exercise
  7. {
  8. class MainClass
  9. {
  10. public static void Main()
  11. {
  12. string[] text = Console.ReadLine()
  13. .Split(new char[]{' ', ',', '.', '!', '?'},StringSplitOptions.RemoveEmptyEntries);
  14. Array.Sort(text);
  15. List<string> result = new List<string>();
  16. foreach (var word in text)
  17. {
  18. if(IsPalindrom(word))
  19. {
  20. if (result.Contains(word))
  21. {
  22. continue;
  23. }
  24. result.Add(word);
  25. }
  26. }
  27. Console.WriteLine(String.Join(", ", result));
  28. }
  29. public static bool IsPalindrom(string s)
  30. {
  31. for (int i = 0; i < s.Length/2; i++)
  32. {
  33. if (s[i] != s[s.Length -i -1])
  34. {
  35. return false;
  36. }
  37. }
  38. return true;
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement