#Java 10, 161 159 152 bytes
s->{var x="";int p=0;for(var c:s)x+=p<(p=c)?c:";"+c;for(var y:x.split(";"))System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ".replaceAll("[^"+y+"]"," "));}
-2 bytes thanks to @Nevay.
-7 byte printing directly instead of returning a String, and converting to Java 10.
Explanation:"
s->{ // Method with String parameter and no return-type
var x=""; // Temp-String
int p=0; // Previous character (as integer), starting at 0
for(var c:s) // Loop (1) over the characters of the input
x+=p<(p=c)? // If the current character is later in the alphabet
// (replace previous `p` with current `c` afterwards)
c // Append the current character to Temp-String `x`
: // Else:
";"+c; // Append a delimiter ";" + this character to Temp-String `x`
for(var y:x.split(";")) // Loop (2) over the String-parts
System.out.println( // Print, with trailing new-line:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
// Take the alphabet,
.replaceAll("[^"+y+"]"," "));}
// and replace all letters not in the String-part with a space
The first part of the method splits the input-word into parts with a delimiter.
For example: CODEGOLF
→ CO;DEGO;L;F
or BALLOON
→ B;AL;LO;O;N
.
The second part loops over these parts, and uses the regex [^...]
to replace everything that isn't matched with a space.
For example .replaceAll("[^CO]"," ")
leaves the C
, and O
, and replaces everything else with a space.