Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 01_02_Task2_3_Format_Lines.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream> //for std::cout
- #include <string>
- #include <sstream>
- #include <iomanip>
- #include <cctype> //char toupper, tolower
- #include <vector>
- #include <iterator> //for std::ostream_iterator
- #include <algorithm> //for std::copy
- #include <utility> //pair<vey, value>
- using namespace std;
- void PrintV(vector<string> v)
- {
- std::copy(v.begin(), v.end(), ostream_iterator<string>(cout, ", "));
- }
- int main()
- {
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- string line;
- getline(cin, line);
- ostringstream oss;
- while (line != "###")
- {
- oss << " " << line << " ";
- getline(cin, line);
- }
- string allLines = oss.str();
- cout << allLines << endl;
- int width;
- cin >> width;
- ostringstream oss2; string word;
- int oss2Width = 0, wordWidth = 0;
- istringstream iss(allLines);
- while (iss >> word)
- {
- oss2Width = oss2.str().size();
- if (oss2Width + word.size() > width)
- {
- cout << oss2.str() << endl;
- oss2.str("");
- oss2.clear();
- oss2 << word << " ";
- }
- else
- {
- oss2 << word << " ";
- }
- }
- cout << oss2.str();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement