Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace EX3
  9. {
  10. class Program
  11. {
  12.  
  13. static bool pal(string cuvant)
  14. {
  15. Stack litere = new Stack();
  16. char[] l = cuvant.ToArray();
  17. int i = 0;
  18. for (i = 0; i < l.Length / 2; i++)
  19. {
  20. litere.Push(l[i]);
  21. }
  22.  
  23. if (l.Length % 2 == 1)
  24. {
  25. i++;
  26. }
  27.  
  28. for (; i < l.Length; i++)
  29. {
  30. if (l[i] != (char)litere.Pop()) return false;
  31. }
  32. return true;
  33. }
  34.  
  35.  
  36. static void Main(string[] args)
  37. {
  38.  
  39. Console.Write("Cuvant=");
  40. string cuvant = Console.ReadLine();
  41.  
  42. if (pal(cuvant))
  43. {
  44. Console.WriteLine("Palindrom");
  45. }
  46. else
  47. {
  48. Console.WriteLine("Nu este palindrom");
  49. }
  50.  
  51. Console.ReadKey();
  52.  
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement