• + 0 comments

    Scala

    import scala.io.StdIn.readLine
    
    object Solution {
    
        def main(args: Array[String]) {
            def swap(str: List[Char]): List[Char] = {
                def swap(res: List[Char], str: List[Char]): List[Char] = {
                    str match {
                        case a :: b :: tail => swap(res :+ b :+ a, tail)
                        case Nil  => res
                    }
                }
                swap(Nil, str)
            }
    
            val n = readLine().toInt
    
            for (i <- 1 to n) {
                val str = readLine()
    
                println(swap(str.toList).mkString)
            }
        }
    }