desislava_topuzakova

6. Palinrom

Mar 26th, 2022
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06._Palindrom
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //aba -> aba
  10. //1a1 -> 1a1
  11. string text = Console.ReadLine();
  12. //текстът на обратно
  13. string reversedText = reverseString(text);
  14.  
  15. if (text == reversedText)
  16. {
  17. //палиндром
  18. Console.WriteLine("True");
  19. }
  20. else
  21. {
  22. Console.WriteLine("False");
  23. }
  24.  
  25. }
  26. static string reverseString(string text)
  27. {
  28. //text = "table";
  29. string reversedString = ""; //обърнатия текст -> "elbat"
  30.  
  31. //от последния към първия символ
  32. for (int position = text.Length - 1; position >= 0; position--)
  33. {
  34. char currentSymbol = text[position];
  35. reversedString += currentSymbol;
  36. }
  37.  
  38. return reversedString;
  39. }
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment