Advertisement
GraionDilach

Alfüggvényes palindrom

Nov 28th, 2011
196
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. namespace ConsoleApplication11
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string Line;
  13.             Console.WriteLine("Kérem a sort:");
  14.             do
  15.             {
  16.                 Line = Console.ReadLine();
  17.             }
  18.             while (Line.Length == 0);
  19.  
  20.             if (Palindrom(Line))
  21.             {
  22.                 Console.WriteLine("A sor palindrom volt.");
  23.             }
  24.             else
  25.             {
  26.                 Console.WriteLine("A sor nem volt palindrom.");
  27.             }
  28.  
  29.         }
  30.  
  31.         static bool Palindrom(string Sor)
  32.         {
  33.             for (int i = 0, j = Sor.Length - 1; i < j; i++, j--) {
  34.                 if (Sor[i] != Sor[j])
  35.                 {
  36.                     return false;
  37.                 }
  38.             }
  39.             return true;
  40.         }
  41.     }
  42. }
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement