[cpp] #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; class JustifyText{ public: vector<string> format( vector<string> text ){ /*find the max length*/ int max_length = 0; for(int i=0; i<text.size(); ++i ) if( text[i].length() > max_length ) max_length = text[i].length(); vector<string> result = text; /*padding every string*/ for(int i=0; i<result.size(); ++i) if( result[i].length() < max_length ){ reverse( result[i].begin(), result[i].end() ); for( int k=result[i].length(); k<max_length; ++k ) result[i].push_back(' '); reverse( result[i].begin(), result[i].end() ); } return result; } private: };