Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int w;
- cout << "Enter w: ";
- cin >> w;
- string words[6] = {"WELCOME", "TO", "CCC", "GOOD", "LUCK", "TODAY"};
- for (int i = 0, j = 0; i < 6 && j < 6; ++i)
- {
- string line = "";
- int wordsThisLine = 0;
- for (; j < 6; ++j)
- {
- if (line.length() + words[j].length() <= w) line += words[j] + ".";
- else break;
- ++wordsThisLine;
- }
- line = line.substr(0, line.length() - 1);
- if (wordsThisLine > 1)
- {
- for (int q = 0; line.length() < w; ++q)
- {
- if (q >= line.length()) q = 0;
- if (line[q] == '.')
- {
- line.insert(q, ".");
- ++q;
- }
- }
- }
- cout << line << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment