Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Palindrome-detection/C-sharp/palindrome-detection-1.cs
Normal file
21
Task/Palindrome-detection/C-sharp/palindrome-detection-1.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
class Program
|
||||
{
|
||||
static string Reverse(string value)
|
||||
{
|
||||
char[] chars = value.ToCharArray();
|
||||
Array.Reverse(chars);
|
||||
return new string(chars);
|
||||
}
|
||||
|
||||
static bool IsPalindrome(string value)
|
||||
{
|
||||
return value == Reverse(value);
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(IsPalindrome("ingirumimusnocteetconsumimurigni"));
|
||||
}
|
||||
}
|
||||
15
Task/Palindrome-detection/C-sharp/palindrome-detection-2.cs
Normal file
15
Task/Palindrome-detection/C-sharp/palindrome-detection-2.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
static bool IsPalindrome(string text)
|
||||
{
|
||||
return text == new String(text.Reverse().ToArray());
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(IsPalindrome("ingirumimusnocteetconsumimurigni"));
|
||||
}
|
||||
}
|
||||
17
Task/Palindrome-detection/C-sharp/palindrome-detection-3.cs
Normal file
17
Task/Palindrome-detection/C-sharp/palindrome-detection-3.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
static class Program
|
||||
{
|
||||
//As an extension method (must be declared in a static class)
|
||||
static bool IsPalindrome(this string sentence)
|
||||
{
|
||||
for (int l = 0, r = sentence.Length - 1; l < r; l++, r--)
|
||||
if (sentence[l] != sentence[r]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("ingirumimusnocteetconsumimurigni".IsPalindrome());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue