• + 0 comments

    Scala, using ScanLeft:

    object Solution {
        import scala.io.StdIn.{readInt, readLine}
    
        def main(args: Array[String]): Unit =
            (1 to readInt).map(_ => rotateAll(readLine)).foreach(println)
    
        def rotateAll(s: String): String = 
            (1 to s.length).scanLeft(s){ case (s, _) => rotate1(s) }.tail.mkString(" ")
    
        def rotate1(s: String): String = 
            s.tail.foldRight(List(s.head))(_ :: _).mkString
    }