src2020/4061_clear/clear.cpp

24 lines
493 B
C++

#include <cstring>
#include <iostream>
using namespace std;
int main()
{
int n, k, now = 0;
string a[101];
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (now + a[i].size() <= k) {
if (now > 0) {
cout << " ";
}
} else {
cout << endl;
now = 0;
}
cout << a[i];
now += a[i].size();
}
}