Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _08112ACW2
- {
- class Program
- {
- static bool palinCheck(string userInput)
- {
- //Inits
- string x;
- bool f;
- int a, z, g;
- char[] punctArray = { ' ', ',', ';', '!', '?', '.' };
- x = userInput;
- g = x.Length;
- z = g - 1;
- a = 0;
- if (g == 1)
- { /* if the input is only one character it is a palindrome, we don't need to check */
- f = true; /* this is unneeded, can simply be set to true on initalization */
- }
- else
- {
- f = true;
- while (f && a < z)
- {
- while (punctArray.Contains<char>(x[a]))
- { /* skip punctuation on inputs */
- a++;
- }
- while (punctArray.Contains<char>(x[z]))
- {
- z--;
- }
- if (x[a].ToString().ToUpper() == x[z].ToString().ToUpper())
- { /* check inputs from both ends are equal */
- a++;
- z--;
- }
- else
- {
- f = false; /* if any are unequal it isn't a palindrome */
- }
- }
- }
- //if (!f)
- //{
- // return false;
- //}
- //else
- //{
- // return true;
- //}
- return f;
- }
- public static void Main()
- {
- string[] testInputs = new string[5]
- {
- "hello world",
- "yo yo oy oy",
- " 23 3!!2",
- "./\\/ap:",
- "129hfknjas"
- };
- foreach (string test in testInputs)
- {
- Console.WriteLine(palinCheck(test));
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement