-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Solution.java
39 lines (32 loc) · 984 Bytes
/
Solution.java
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
// github.com/RodneyShag
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/* Read input */
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
scan.close();
s = removeLeadingNonLetters(s);
/* Check special cases */
if (s.length() == 0) {
System.out.println(0);
return;
}
/* Split on all non-alphabetic characters */
String[] words = s.split("[^a-zA-Z]+");
/* Print output */
System.out.println(words.length);
for (String word : words) {
System.out.println(word);
}
}
private static String removeLeadingNonLetters(String str) {
int i;
for (i = 0; i < str.length(); i++) {
if (Character.isLetter(str.charAt(i))) {
break;
}
}
return str.substring(i);
}
}