#Java 810, 161 159159 152 bytes
s->{Stringvar x="",r=x;intx="";int p=0;for(charvar c:s)x+=p<(p=c)?c:";"+c;for(Stringvar y:x.split(";"))r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ".replaceAll("[^"+y+"\n]""[^"+y+"]"," ");return r;);}
-2 bytes thanks to @Nevay.
-7 byte printing directly instead of returning a String, and converting to Java 10.
Try it here.Try it here.
s->{ // Method with String as both parameter and no return-type
String x="",var x=""; // Temp-String
r=x; // Result-String
int p=0; // Previous character (as integer), starting at 0
for(charvar 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`
// End of loop (1) (implicit / single-line body)
for(Stringvar y:x.split(";")) // Loop (2) over the String -parts
r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"System.out.println( // Print, with trailing new-line:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
// Take the alphabet,
.replaceAll("[^"+y+"\n]""[^"+y+"]"," "));}
// and replace all except the characters with a space
// End of loop (2) (implicit / single-line body)
return r; //letters not Returnin the result-String
} //-part Endwith ofa methodspace
The second part loops over these parts, and uses the regex [^...\n]]
to replace everything that isn't matched with a space.
For example .replaceAll("[^CO\n]""[^CO]"," ")
leaves the C
, O
and new-line \nO
, and replaces everything else with a space.