19/12/18 21:05:50.74 WdZQqUwr.net
>>359
Rでrle関数を使って楽々
MaxRepChar <- function(s) {
if (!nchar(s)) return(invisible())
r <- rle(unlist(strsplit(s, "")))
b <- r$lengths == max(r$lengths)
cat(sprintf('("%s", %d)', r$values[b], r$lengths[b]), sep = ", "); cat("\n")
}
MaxRepChar("acgtaattgaaagggtctt")
MaxRepChar("スレリンク(tech板)")
-- 実行結果 --
("a", 3), ("g", 3)
("t", 2), ("/", 2), ("8", 2), ("2", 2)