@[longyuy](/user/1234608)
```python
n,k=map(int,input().split())
s=input().split()
l=0
for i in s:
if l+len(i)<=k:
l+=len(i)
print(i,end=' ')
else:
l=len(i)
print()
print(i,end=' ')
```
by hyh0174 @ 2024-04-28 21:29:40
```c
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
ll N,K;
vector<string> words;
int main()
{
cin>>N>>K;
string word;
while(cin>>word)
{
words.push_back(word);
}
ll len=0;
for(const string& w : words)
{
if(len+w.length()<=K)
{
if(len>0)
{
cout<<" ";
}
cout<<w;
len+=w.size();
}
else
{
cout<<endl<<w;
len=w.size();
}
}
return 0;
}
```
@[longyuy](/user/1234608)
by guanhetian @ 2024-04-28 21:45:37
@[guanhetian](/user/937470) 谢谢
by longyuy @ 2024-04-29 22:28:21