jli

CCC 2009 Junior Problem 4

jli
Apr 9th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int w;
  9.     cout << "Enter w: ";
  10.     cin >> w;
  11.  
  12.     string words[6] = {"WELCOME", "TO", "CCC", "GOOD", "LUCK", "TODAY"};
  13.  
  14.     for (int i = 0, j = 0; i < 6 && j < 6; ++i)
  15.     {
  16.         string line = "";
  17.         int wordsThisLine = 0;
  18.  
  19.         for (; j < 6; ++j)
  20.         {
  21.             if (line.length() + words[j].length() <= w) line += words[j] + ".";
  22.             else break;
  23.             ++wordsThisLine;
  24.         }
  25.  
  26.         line = line.substr(0, line.length() - 1);
  27.  
  28.         if (wordsThisLine > 1)
  29.         {
  30.             for (int q = 0; line.length() < w; ++q)
  31.             {
  32.                 if (q >= line.length()) q = 0;
  33.  
  34.                 if (line[q] == '.')
  35.                 {
  36.                     line.insert(q, ".");
  37.                     ++q;
  38.                 }
  39.             }
  40.         }
  41.  
  42.         cout << line << endl;
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment