ABC #019 B : 高橋くんと文字列圧縮
問題リンク : B: 高橋くんと文字列圧縮 - AtCoder Beginner Contest 019 | AtCoder
問題概要 :
英小文字からなる文字列が与えられる
それらを問題文中に書かれている方法で圧縮しその結果を出力せよ
解法 :
圧縮して出力する
コード :
let rec solve s i = if ( i >= ( String.length s ) ) then () else begin Printf.printf "%c" s.[i] ; let rec counter j = if ( j >= ( String.length s ) || s.[j] <> s.[i] ) then 0 else 1 + counter (j+1) in let temp = counter i in Printf.printf "%d" temp ; solve s ( i + temp ) end;; let s = Scanf.scanf "%s" ( fun s -> s ) in solve s 0;; print_newline();;