Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _9.Palindrome_Index
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<char> str = Console.ReadLine().ToList();
- bool palindromeOrNot = isItAPalindrome(str);
- if (palindromeOrNot)
- {
- Console.WriteLine("-1");
- }
- else
- {
- for (int ch = 0; ch < str.Count; ch++)
- {
- char oldStr = str[ch];
- str.RemoveAt(ch);
- palindromeOrNot = isItAPalindrome(str);
- if (palindromeOrNot)
- {
- Console.WriteLine(ch);
- break;
- }
- str.Insert(ch, oldStr);
- }
- }
- }
- private static bool isItAPalindrome(List<char> str)
- {
- int rightIndex = str.Count - 1;
- int leftIndex = 0;
- while (rightIndex >= leftIndex)
- {
- if (str[rightIndex] != str[leftIndex])
- {
- return false;
- }
- rightIndex--;
- leftIndex++;
- }
- return true;
- }// end of isItAPalindrome
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement