• + 0 comments

    Easy solution

    include

    using namespace std;

    int main() { string st; cin>>st;

    string noSpace="";
    
    for(int i=0;i<st.length();i++){
        if(st[i]!=' '){
            noSpace+=st[i];
        }
    }
    
    int size=noSpace.length();
    
    //cout<<size<<endl;
    
    int fl=floor(sqrt(size));
    int cl=ceil(sqrt(size));
    
    int mul=fl*cl;
    

    // cout<

        while(mul<size){
            fl+=1;
            mul=fl*cl;
        }
    }
    
    vector<vector<char>>ans;
    
    int x=0;
    
    
        for(int i=0;i<fl;i++){
            vector<char>temp;
            for(int j=0;j<cl;j++){
                if(x<size){
                    temp.push_back(noSpace[x]);
                    x+=1;
                }else{
                    temp.push_back('-');
                }
            }
            ans.push_back(temp);
        }
    
    
    string ans1="";
    for(int i=0;i<ans[0].size();i++){
        for(int j=0;j<ans.size();j++){
            if(ans[j][i]!='-'){
                ans1+=ans[j][i];
            }
        }
        ans1+=" ";
    
    }
    
    cout<<ans1<<endl;
    
    
    
    
    
    return 0;
    

    }