-
-
Save waynejo/3bbdfef9652a24a02f5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.{FileOutputStream, FileInputStream} | |
import scala.io.StdIn | |
object Main extends App { | |
Console.setIn(new FileInputStream("B-small-practice.in")) | |
Console.setOut(new FileOutputStream("B-small-practice.out")) | |
def solve(input: String): BigInt = { | |
val in = "0" + input | |
val (head, tail) = in.splitAt(in.sliding(2, 1).toList.lastIndexWhere((x) => x(0) < x(1)) + 1) | |
val i = tail.zipWithIndex.filter(_._1 > head.last).min._2 | |
BigInt(head.init + tail(i) + tail.updated(i, head.last).sorted) | |
} | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach { n => | |
val input = StdIn.readLine() | |
println(s"Case #$n: ${solve(input)}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment