Advertisement
Aborigenius

Nilandromes-NotFixed

Aug 23rd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Nilandromes
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.  
  15.             while (input != "end")
  16.             {
  17.                 string nillandrome = Nillandrome(input);
  18.                 if (nillandrome != "")
  19.                 {
  20.                     Console.WriteLine(nillandrome);
  21.                 }
  22.                 input = Console.ReadLine();
  23.             }
  24.         }
  25.         public static string Nillandrome(string input)
  26.         {
  27.  
  28.             int middleIndex = input.Length / 2;
  29.             string border = "";
  30.             int leftIndex = 0;
  31.             for (int i = middleIndex + 1; i < input.Length; i++)
  32.             {
  33.                 if (input[leftIndex] == input[i])
  34.                 {
  35.                     border += input[i];
  36.                     leftIndex++;
  37.                 }
  38.                 else
  39.                 {
  40.                     border = "";
  41.                     leftIndex = 0;
  42.                     if (input[i] == input[leftIndex])
  43.                     {
  44.                         border += input[i];
  45.                         leftIndex++;
  46.                     }
  47.                 }
  48.             }
  49.  
  50.             if (border != "")
  51.             {
  52.                 int leftIndexMiddle = input.IndexOf(border);
  53.                 int rightIndexMiddle = input.LastIndexOf(border);
  54.  
  55.                 string middle = input.Substring(leftIndexMiddle + border.Length,
  56.                     rightIndexMiddle - leftIndexMiddle - border.Length);
  57.                 if (middle != "")
  58.                 {
  59.                     return middle + border + middle;
  60.                 }
  61.             }
  62.  
  63.             return null;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement