#include #include #include #include using namespace std; struct page { vector p; int column, row; int cnum, cspace, width; page(int plen, int _cnum, int _width, int _cspace) : p(plen, ""), column(0), row(0), cnum(_cnum), width(_width), cspace(_cspace) {} void add_space() { for (int i = 0; i < p.size(); i++) { p[i] += string(cspace, '.'); } } void fill_column() { if (row == 0) { return; } for (; row < p.size(); row++) { p[row] += string(width, '.'); } row = 0; column++; } void print() { // Something wrong while (column < cnum) { add_chopped_string(""); fill_column(); } for (int i = 0; i < p.size(); i++) { cout << p[i] << endl; } cout << "#" << endl; } void clear() { p = vector(p.size(), ""); } void add_chopped_string(const string &s) { if (column > 0 && row == 0) { add_space(); } p[row] += (s + string(width - s.length(), '.')); row++; if (row >= p.size()) { row = 0; column++; } if (column >= cnum) { print(); clear(); column = 0; } } void add_string(const string &s) { if (s == "") { add_chopped_string(""); } for (int i = 0; i < s.length(); i += width) { add_chopped_string(s.substr(i, min(width, (int)(s.length() - i)))); } } }; int main() { int plen, cnum, width, cspace; string s; while (cin >> plen && plen > 0) { cin >> cnum >> width >> cspace; page p(plen, cnum, width, cspace); getline(cin, s); // dummy while (true) { getline(cin, s); if (s == "?") { break; } p.add_string(s); } if (p.row > 0 || p.column > 0) { p.fill_column(); p.print(); } cout << "?" << endl; } return 0; }