C/C++の宿題を片付けます 81代目

このエントリーをはてなブックマークに追加
950デフォルトの名無しさん
>>947
#include <iostream>
#include <string>
using namespace std;
const int maxcol = 70;
int main()
{
    string s;
    int ncol = 0;
    while (cin >> s) {
        if (s.size() > maxcol) {
            cout << flush;
            cerr << "Too long word: " << s << endl;
        } else if (ncol == 0) {
            cout << s;
            ncol += s.size();
        } else if (ncol + s.size() + 1 < maxcol) {
            cout << ' ' << s;
            ncol += s.size() + 1;
        } else {
            cout << '\n' << s;
            ncol = s.size();
        }
    }
    cout << endl;
    return 0;
}