#include #include #include std::vector split(const std::string& s) { std::vector ret; std::string::size_type i = 0; /* Invariant: we have processed characters [start i, i) */ while (i != s.size()) { /* * Walk to the first non-space character * * Invariant: characters between [start i, current i) are all * spaces */ while (i != s.size() && isspace(s[i])) i++; /* * Find the end of current word * * Invariant: None of the characters between [i, j) are spaces */ std::string::size_type j = i; while (j != s.size() && !isspace(s[j])) j++; /* If we found non-whitespace chars, push to the vector */ if (i != j) { ret.push_back(s.substr(i, j - i)); i = j; } } return ret; } std::string::size_type width(const std::vector& v) { std::string::size_type ret = 0; for (std::vector::const_iterator i = v.begin(); i != v.end(); i++) ret = std::max(ret, i->size()); return ret; } std::vector frame(const std::vector&v) { std::vector ret; std::string::size_type w = width(v); std::string border(w + 4, '*'); ret.push_back(border); for (std::string::size_type i = 0; i != v.size(); i++) ret.push_back("* " + v[i] + std::string(w - v[i].size(), ' ') + " *"); ret.push_back(border); return ret; } std::vector vcat( const std::vector& v1, const std::vector& v2) { std::vector ret = v1; for (std::vector::const_iterator i = v2.begin(); i < v2.end(); i++) ret.push_back(*i); return ret; } std::vector hcat( const std::vector& v1, const std::vector& v2) { std::vector ret; std::string::size_type w1 = width(v1) + 1; std::vector::size_type i = 0, j = 0; while (i != v1.size() || j != v2.size()) { std::string s; if (i != v1.size()) s = v1[i++]; s += std::string(w1 - s.size(), ' '); if (j != v2.size()) s += v2[j++]; ret.push_back(s); } return ret; } int main(void) { std::string s; while (getline(std::cin, s)) { std::vector vec = split(s); vec = frame(vec); for (std::vector::const_iterator i = vec.begin(); i < vec.end(); i++) { std::cout << *i << std::endl; } } std::string a = "Vai curintia fela da puta"; std::vector v1 = split(a); v1 = frame(v1); std::string b = "Curintiano sao tudo paus do caralho porra locas"; std::vector v2 = split(b); std::vector v3 = hcat(v1, v2); for (std::vector::const_iterator i = v3.begin(); i < v3.end(); i++) { std::cout << *i << std::endl; } return 0; }