• + 0 comments
    class Result
    {
    
        /*
         * Complete the 'encryption' function below.
         *
         * The function is expected to return a STRING.
         * The function accepts STRING s as parameter.
         */
    
        public static string encryption(string s)
        {
            s = s.Replace(" ", "");
            int sz = s.Length;
            double qrt = Math.Sqrt(sz);
            int slc = (int)Math.Ceiling(qrt);
            int slf = (int)Math.Floor(qrt);
            
            char[,] ans = new char[slc, slc];
            
            int lstjidx = 0;
            for(int i = 0; i < slc; i++){
                for (int j = 0; j < slc && lstjidx < sz; j++, lstjidx++){
                    ans[i, j] = s[lstjidx];
                }
            }
            
            string ans2 = "";
            for(int i = 0; i < slc; i++){
                for (int j = 0; j < slc; j++){
                    ans2 += ans[j, i];
                }
               if (i < slc - 1) ans2 += " ";
            }
            
            return ans2;
        }
    
    }
    

    in C# : sample cases shows WA while all expected and my output are exact same (not extra white character or new line characters?

    textWriter.Flush();
        textWriter.Close();
    }
    

    }