Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <list>
- using namespace std;
- int main() {
- string line, word;
- getline(cin, line);
- list<string> words;
- while (line != "###") {
- istringstream ss(line);
- while (ss >> word) {
- words.push_back(word);
- }
- getline(cin, line);
- }
- int rowLength;
- cin >> rowLength;
- string outputLine = "";
- for (auto& w : words) {
- if (outputLine.length() + w.length() <= rowLength) {
- outputLine += w + ' ';
- }
- else {
- cout << outputLine.substr(0, outputLine.size() - 1) << endl;
- outputLine = w + ' ';
- }
- }
- cout << outputLine << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement