fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ExtractPalindromes
  5. {
  6. class Program
  7. {
  8. //Write a program that extracts from a
  9. //given text all palindromes, e.g. "ABBA", "lamal", "exe".
  10. static void Main(string[] args)
  11. {
  12. string text = "Also visit <a href=www.devbg.org>" +
  13. " dd orum</a> to discuss ABA pesho@abv.bg the courses.</p> Also visit mary.ana@gmail.com <a href=www.devbg.org>" +
  14. " our forum</a> andes1sedna seliandur@yahoo.com to fafa discuss affathe courses.</p>";
  15. string[] words = text.Split(' ');
  16.  
  17. foreach (var item in words)
  18. {
  19. if(isPalindrome(item))
  20. Console.WriteLine(item);
  21. }
  22. }
  23.  
  24. public static bool isPalindrome(string word)
  25. {
  26. bool isPalindrome = true;
  27.  
  28. for (int i = 0; i < word.Length / 2; i++)
  29. {
  30. if (word[i] != word[word.Length-1 - i])
  31. {
  32. isPalindrome = false;
  33. }
  34. }
  35. return isPalindrome;
  36. }
  37. }
  38. }
Success #stdin #stdout 0.03s 36928KB
stdin
Standard input is empty
stdout
dd
ABA
andes1sedna