Last active
October 13, 2016 11:53
-
-
Save dretax/cd5e1b196f888876392647c5cefc032b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace iziprogzh4 | |
{ | |
internal class Program | |
{ | |
internal static bool IsPalindrome(string value) | |
{ | |
//legyen apa a szó | |
int min = 0; // minimuma, alapvetően 0 lehet egy karakter hossza ha üres | |
int max = value.Length - 1; // -1 a hosszúságból, apa szó esetén ez 2 | |
while (true) // amíg kurvára nem tudjuk mi a faszom ez a szó addig megy a ciklus | |
{ | |
// ha a minimum valahogy nagyobb mint a max akkor instában true (ha esetleg a megadott szó "") | |
// persze lentebb majd ott fog csökkenni a max érték | |
if (min > max) | |
{ | |
return true; | |
} | |
char a = value[min]; // a szó 0.k eleme ami apa függvényében a | |
char b = value[max]; // a szó maximuma ami apa szónak a 3. eleme lesz így: apa[2], ez a 3. betű és az a | |
// ha a két betű nem egyenlő, akkor megállítjuk a ciklust mertúgysem lesz az. | |
// persze ha megyegyezik, ami az apa szó esetében megfog akkor tovább megyünk | |
if (char.ToLower(a) != char.ToLower(b)) | |
{ | |
return false; | |
} | |
// itt növeljük a minimumot, és csökkentjük a maximumot, egyre beljebb megyünk a szón | |
min++; | |
max--; | |
} | |
} | |
internal static void Main() | |
{ | |
Console.WriteLine(IsPalindrome("cia")); //false | |
Console.WriteLine(IsPalindrome("mia")); //false | |
Console.WriteLine(IsPalindrome("khalifa")); //false | |
Console.WriteLine(IsPalindrome("grubi")); //false | |
Console.WriteLine(IsPalindrome("meleg")); //false | |
Console.WriteLine(IsPalindrome("apa")); //true | |
Console.WriteLine(IsPalindrome("inni")); //true | |
Console.WriteLine(IsPalindrome("INNI")); //true | |
Console.WriteLine(IsPalindrome("iNNi")); //true | |
Console.WriteLine(IsPalindrome("feka")); //false | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment