• + 0 comments

    include

    include

    include

    using namespace std;

    string encryption(string s) { string noSpaces = ""; for (char c : s) { if (c != ' ') noSpaces += c; }

    int L = noSpaces.length();
    int rows = floor(sqrt(L));
    int cols = ceil(sqrt(L));
    
    if (rows * cols < L) rows++;
    
    string result = "";
    for (int c = 0; c < cols; c++) {
        if (c > 0) result += " ";
        for (int r = 0; r < rows; r++) {
            int idx = r * cols + c;
            if (idx < L) {
                result += noSpaces[idx];
            }
        }
    }
    
    return result;
    

    }

    int main() { string s; getline(cin, s); cout << encryption(s) << endl; return 0; }