-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.cpp
More file actions
41 lines (34 loc) · 748 Bytes
/
text.cpp
File metadata and controls
41 lines (34 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
// uncomment the following lines if you want to read/write from files
// ifstream cin("input.txt");
// ofstream cout("output.txt");
// input data
int N, K;
cin >> N >> K;
string W[N];
for(int i=0; i<N; i++)
cin >> W[i];
// insert your code here
int l=0;
for (int i=0; i<N; i++) {
if (l == 0) {
cout << W[i];
l += W[i].size();
} else {
if (l +1 + W[i].size() <= K) {
cout << " " << W[i];
l += W[i].size() +1;
} else {
cout << endl;
l = 0;
i--;
}
}
}
return 0;
}