Advertisement
Guest User

Untitled

a guest
Nov 10th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             string s = "Einhorn roh? Nie!";
  4.             string low = s.ToLower();
  5.             bool IstPalindrom = true;
  6.             int linkerIndex = 0, rechterIndex=low.Length-1;
  7.  
  8.             while (linkerIndex < rechterIndex)
  9.             {
  10.                     while (!char.IsLetter(s[linkerIndex]))
  11.                         linkerIndex++;
  12.                     while (!char.IsLetter(s[rechterIndex]))
  13.                         rechterIndex--;
  14.  
  15.                     if (low[linkerIndex] != low[rechterIndex])
  16.                     {
  17.                         IstPalindrom = false;
  18.                         break;
  19.                     }
  20.                     linkerIndex++;
  21.                     rechterIndex--;
  22.             }            
  23.             if (IstPalindrom)
  24.                 Console.WriteLine("{0} ist ein Palindrom", s);
  25.             else
  26.                 Console.WriteLine("{0} ist KEIN Palindrom", s);
  27.  
  28.             }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement