svetlozar_kirkov

Extract polindromes (Exercise)

Oct 11th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleTests
  4. {
  5.     class ConsoleTests
  6.     {
  7.         static void Main()
  8.         {
  9.             string text = "abba lamal exe bla test uni ABBA polindromes";
  10.             string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  11.  
  12.             bool polindrome;
  13.             foreach (var word in words)
  14.             {
  15.                 polindrome = true;
  16.                 for (int i = 0; i < word.Length / 2; i++)
  17.                 {
  18.                     if (word[i] != word[word.Length - i - 1])
  19.                     {
  20.                         polindrome = false;
  21.                     }
  22.                 }
  23.                 if (polindrome)
  24.                 {
  25.                     Console.WriteLine(word);
  26.                 }
  27.             }
  28.  
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment