fork download
  1. library(stringr)
  2.  
  3. lexi <- function(x) {
  4. opt <- vector(length = str_length(x))
  5. for(i in 1:str_length(x))
  6. opt[i] <- str_sub(x, i)
  7. sub <- order(opt)[1] - 1
  8. new <- str_c(opt[sub+1], str_sub(x, 1, sub), collapse = "")
  9. return(cat(sub, new, "\n"))
  10. }
  11.  
  12. input <- "aabbccddbbaabb\nonion\nbbaaccaadd\nalfalfa\nweugweougewoiheew\npneumonoultramicroscopicsilicovolcanoconiosis"
  13. input <- str_split(input, "\n")[[1]]
  14. invisible(sapply(input, lexi))
Success #stdin #stdout 0.22s 182464KB
stdin
Standard input is empty
stdout
10 aabbaabbccddbb 
2 ionon 
2 aaccaaddbb 
6 aalfalf 
14 eewweugweougewoih 
12 amicroscopicsilicovolcanoconiosispneumonoultr