Skip to content

Instantly share code, notes, and snippets.

@Soulstorm50
Created December 24, 2016 12:35
Show Gist options
  • Save Soulstorm50/35fb4c93b378f1d46aea888a061d9f2a to your computer and use it in GitHub Desktop.
Save Soulstorm50/35fb4c93b378f1d46aea888a061d9f2a to your computer and use it in GitHub Desktop.
Палиндром C#
using System;
using System.Text.RegularExpressions;
public class Palindrom
{
public static string Reverser(string a)
{
char[] arr = a.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
public static string Palindromer(string x)
{
string y = Reverser(x);
Console.WriteLine(y);
if (Equals(x, y))
return "Палиндром";
else
return "Не палиндром";
}
public static void Main()
{
Console.Title = "Проверка на палиндромность.";
Console.WriteLine("Введите тестируемую строку");
string pattern = @"\.+?|\,+?|\ +?|\-+?|\:+?";
string input = Console.ReadLine();
string str = input.ToLower();
str = (Regex.Replace(str, pattern, string.Empty));
Console.WriteLine(input + " - " + Palindromer(str));
Console.WriteLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment