Advertisement
Guest User

Untitled

a guest
May 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System.IO;
  2. using System;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         string s = Console.ReadLine();
  9.             int n = 0;
  10.             int m = s.Length - 1;
  11.             bool polindrom = true;
  12.             bool have = false;
  13.             while (n <= m)
  14.             {
  15.                 if (s[n] != s[m])
  16.                 {
  17.                     polindrom = false;
  18.                 }
  19.                 if (s[m] != s[0] || s[n] != s[0])
  20.                 {
  21.                     have = true;
  22.                 }
  23.                 n += 1;
  24.                 m -= 1;
  25.             }
  26.            
  27.             if (!have)
  28.             {
  29.                 Console.WriteLine(-1);
  30.             }
  31.             else
  32.             {
  33.                 if (polindrom)
  34.                 {
  35.                     Console.WriteLine(s.Length-1);
  36.                 }
  37.                 else
  38.                 {
  39.                     Console.WriteLine(s.Length);
  40.                 }
  41.             }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement