Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Palindrome using stack
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Stack<char> cstack = new Stack<char>(); string input = "MALAYALAM"; var inputToUpper = input.ToUpper(); /*assuming case senstivity is not to be considered */ foreach (char c in inputToUpper) { cstack.Push(c); } bool isPalindrome = true; var noOfItems = cstack.Count; for(int i=0; i< noOfItems ; i++) { if (inputToUpper[i] != cstack.Pop()) { isPalindrome = false; break; } } if (isPalindrome) { Console.WriteLine("Palindrome"); } else { Console.WriteLine("Non Palindrome"); } } } }
run
|
edit
|
history
|
help
0
Animal generator (Under construction!)
Geração de HASH do SKU pra enviar para Vtex
Reward
C# constructor in inheritance
StackOverflowException
Staircase
eryjuyhtgrfesdsadcfg
C# programming exercise 2
Hareket
AdventCode