Advertisement
didak1t

Палиндром ли е, не е ли ?

Jan 4th, 2025
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | Source Code | 0 0
  1.  
  2. string input = Console.ReadLine();
  3. char[] temp = new char[input.Length];
  4.  
  5. int index = 0;
  6.  
  7. for (int i = 0; i < input.Length; i++)
  8. {
  9.     if (char.IsLetterOrDigit(input[i]))
  10.     {
  11.         temp[index] = char.ToLower(input[i]);
  12.         index++;
  13.     }  
  14. }
  15.  
  16. string cleanedInput = new string(temp, 0, index);
  17.  
  18. bool isPalindrome = cleanedInput.SequenceEqual(cleanedInput.Reverse());
  19.  
  20. if (isPalindrome)
  21. {
  22.     Console.WriteLine("ДА");
  23. }
  24. else
  25. {
  26.     Console.WriteLine("НЕ");
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement