Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created July 29, 2016 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waynejo/5d604066e64335d3967a86bc0022d3b8 to your computer and use it in GitHub Desktop.
Save waynejo/5d604066e64335d3967a86bc0022d3b8 to your computer and use it in GitHub Desktop.
package Main
import java.io.{FileInputStream, FileOutputStream}
import scala.annotation.tailrec
import scala.io.StdIn
object Main extends App {
Console.setIn(new FileInputStream("example.in"))
Console.setIn(new FileInputStream("A-small-practice.in"))
Console.setOut(new FileOutputStream("A-small-practice.out"))
Console.setIn(new FileInputStream("A-large-practice.in"))
Console.setOut(new FileOutputStream("A-large-practice.out"))
def solve(inputs:String): String = {
(inputs.head.toString /: inputs.tail)((acc, x) =>
if (acc.head > x) acc + x else x + acc
)
}
val cases = StdIn.readLine().toInt
(1 to cases) foreach { i => {
val inputs = StdIn.readLine()
println(s"Case #$i: ${solve(inputs)}")
}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment