Advertisement
dobroslav_atanasov

Nilapdromes

Apr 3rd, 2017
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.Nilapdromes
  6. {
  7.     public class Nilapdromes
  8.     {
  9.         public static void Main()
  10.         {
  11.             var input = Console.ReadLine();
  12.  
  13.             while (input != "end")
  14.             {
  15.                 var borderFirst = input.Substring(0, input.Length / 2);
  16.                 var borderSecond = string.Empty;
  17.                 var border = string.Empty;
  18.  
  19.                 if (input.Length % 2 == 0)
  20.                 {
  21.                     borderSecond = input.Substring(borderFirst.Length, input.Length - borderFirst.Length);
  22.                 }
  23.                 else
  24.                 {
  25.                     borderSecond = input.Substring(borderFirst.Length + 1, input.Length - borderFirst.Length - 1);
  26.                 }                
  27.  
  28.                 while (true)
  29.                 {
  30.                     if (borderFirst == borderSecond)
  31.                     {
  32.                         border = borderFirst;
  33.                         break;
  34.                     }
  35.                     else if (borderFirst != borderSecond)
  36.                     {
  37.                         borderFirst = borderFirst.Substring(0, borderFirst.Length - 1);
  38.                         borderSecond = borderSecond.Substring(1, borderSecond.Length - 1);
  39.                     }
  40.  
  41.                     if (borderFirst.Length == 0 && borderSecond.Length == 0)
  42.                     {
  43.                         break;
  44.                     }
  45.                 }
  46.  
  47.                 if (border.Length != 0)
  48.                 {
  49.                     var core = input.Remove(input.Length - border.Length, border.Length).Trim();
  50.                     core = core.Remove(0, border.Length).Trim();
  51.                     if (core != "")
  52.                     {
  53.                         var nilapdromes = core + border + core;
  54.                         Console.WriteLine(nilapdromes);
  55.                     }
  56.                 }
  57.  
  58.                 input = Console.ReadLine();
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement