Skip to content

Instantly share code, notes, and snippets.

@theodoreLee
Created August 21, 2015 12:17
Show Gist options
  • Save theodoreLee/61448d55112aa256e440 to your computer and use it in GitHub Desktop.
Save theodoreLee/61448d55112aa256e440 to your computer and use it in GitHub Desktop.
import java.io.FileOutputStream
import scala.io.Source
object ReverseWords {
def solve(str:String) = str.split(' ').reverse.mkString(" ")
def main(args: Array[String]): Unit = {
val INPUT = "B-large-practice.in"
val OUTPUT = INPUT.takeWhile(_ != '.') + ".out"
val isConsole = false
val itr = Source.fromFile(INPUT).getLines()
val stream = if (isConsole) Console.out else new FileOutputStream(OUTPUT)
try {
Console.withOut(stream) {
val sets = itr.next().toInt
(1 to sets).foreach { set =>
println(f"Case #$set: ${solve(itr.next())}")
}
}
} finally {
stream.flush()
if (!isConsole) stream.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment