Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EX3
- {
- class Program
- {
- static bool pal(string cuvant)
- {
- Stack litere = new Stack();
- char[] l = cuvant.ToArray();
- int i = 0;
- for (i = 0; i < l.Length / 2; i++)
- {
- litere.Push(l[i]);
- }
- if (l.Length % 2 == 1)
- {
- i++;
- }
- for (; i < l.Length; i++)
- {
- if (l[i] != (char)litere.Pop()) return false;
- }
- return true;
- }
- static void Main(string[] args)
- {
- Console.Write("Cuvant=");
- string cuvant = Console.ReadLine();
- if (pal(cuvant))
- {
- Console.WriteLine("Palindrom");
- }
- else
- {
- Console.WriteLine("Nu este palindrom");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement