-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword.java
More file actions
41 lines (32 loc) · 861 Bytes
/
Copy pathword.java
File metadata and controls
41 lines (32 loc) · 861 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
import java.lang.*;
import java.util.*;
import java.io.*;
public class word {
public static void main(String[] args) {
File f = new File("word.in");
try(Scanner in = new Scanner(f)){
try(PrintWriter writer = new PrintWriter("word.out", "UTF-8")){
int k = in.nextInt();
int n = in.nextInt();
int flag = 0;
String s;
for(int i = 0;i<k;i++){
s = in.next();
if(flag + s.length() > n){
writer.println();
writer.print(s);
flag = 0;
}else{
if(flag!= 0){
writer.print(" ");
}
writer.print(s);
}
flag += s.length();
}
}catch(IOException e){
}
} catch(IOException e){
}
}
}