fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. // your code goes here
  9. var snake=" tSyrep \n"
  10. + " r p \n"
  11. + " in Sli \n"
  12. + " g Sile\n"
  13. + " Snakes n\n"
  14. + "Ser ylt\n"
  15. + "a eh ilS \n"
  16. + "fe w t \n"
  17. + " emo h \n"
  18. + " Sre ";
  19.  
  20. var result = new Test().f(snake);
  21. Console.WriteLine(result);
  22. }
  23.  
  24. string f(string s){int o=-~s.IndexOf('\n'),m=99;var r=new string(' ',o);(s=r+s+r).Select((c,i)=>{int n=2,e=0,p,w=i%o+i/o;if(c>' '&w<m&&new[]{-1,1,o,-o}.All(d=>(s[i+d]>' '?(e=d)*--n:n)>0))for(m=w,r=""+c+s[p=i+e];new[]{e,o/e,-o/e}.Any(d=>s[p+(e=d)]>' ');)r+=s[p+=e];return i;}).Max();return r;}
  25. }
Success #stdin #stdout 0.01s 29800KB
stdin
Standard input is empty
stdout
SlipperyStringSnakesSilentlySlitherSomewhereSafe