Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int Polyndrom(string st)
- {
- string current;
- int m, maxLength = 0;
- for (int i = 0; i < st.Length; i++)
- {
- current = "";
- m = 1;
- if (st[i] == '*')
- {
- while (((i - m) >= 0 && (i + m) < st.Length) && (st[i - m] == st[i + m]))
- {
- current += st[i - m];
- m++;
- }
- if (current.Length * 2 + 1 > maxLength)
- maxLength = current.Length * 2 + 1;
- }
- }
- return maxLength;
- }
- static void Main(string[] args)
- {
- int num;
- string st;
- Console.WriteLine("String: ");
- st = Console.ReadLine();
- num = Polyndrom(st);
- Console.WriteLine("Longest polyndrom with a '*' in the middle: " +num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement