BWT by m.ukai

open String
open Printf;;while 1=1do
let s=read_line()in
let l=length s-1in
let rec r i=if i>0then((sub s i(l-i+1))^(sub s 0i))::r(i-1)else[s]in
let a=List.sort compare(r l)in
let rec(@)(h::t)i=h=s&(printf"%d "i;printf"
"=List.iter(fun c->printf"%c"c.[l])a)||t@i+1in
a@0done

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page