You are viewing a single comment's thread. Return to all comments →
use list to solve this problem in fsharp
let main argv = let s1 = System.Console.ReadLine() |> Seq.toList let s2 = System.Console.ReadLine() |> Seq.toList let pps (ss:List<char>) = ss |> System.String.Concat |> (fun s -> if s.Length <= 0 then printfn "0" else printfn "%d %s" s.Length s) let zips = ( (if s1.Length < s2.Length then (s1 @ [for i in 1..(s2.Length-s1.Length) do yield System.Char.MinValue]) else s1), (if s1.Length > s2.Length then (s2 @ [for i in 1..(s1.Length-s2.Length) do yield System.Char.MinValue]) else s2)) ||> Seq.zip zips |> Seq.takeWhile (fun (c1,c2) -> c1 = c2) |> Seq.map fst |> Seq.toList |> pps zips |> Seq.skipWhile (fun (c1,c2) -> c1 = c2) |> Seq.fold (fun (o1,o2) (c1,c2) -> ((if c1=System.Char.MinValue then o1 else c1::o1), (if c2=System.Char.MinValue then o2 else c2::o2))) ([], []) |> (fun (o1, o2) -> o1 |> List.rev |> pps o2 |> List.rev |> pps)
Seems like cookies are disabled on this browser, please enable them to open this website
Prefix Compression
You are viewing a single comment's thread. Return to all comments →
use list to solve this problem in fsharp