Advertisement
Krissy

IsPalindrome

Jan 28th, 2013
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7. class Palindromes
  8. {
  9.     static void Main()
  10.     {
  11.         string text = @"Nice blue sky. No exe flying in the sky. ABBA will not come in Bulgaria.
  12.        I don`t know what is lamal, maybe I will find some day. mouseesuom";
  13.         char[] separators = { ' ', ',', '.', '!', '\n', '\r' };
  14.         string[] splitted = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
  15.  
  16.  
  17.         foreach (string word in splitted)
  18.         {
  19.             bool isPalindrome = true;
  20.             for (int j = 0; j < (word.Length / 2); j++)
  21.             {
  22.                 if (word[j] != word[word.Length-1-j])
  23.                 {
  24.                     isPalindrome = false;
  25.                     break;
  26.                 }
  27.             }
  28.             if (isPalindrome&&word.Length>1)
  29.             {
  30.                 Console.WriteLine(word);
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement