Skip to content

Instantly share code, notes, and snippets.

@jinuk17
Last active July 29, 2016 11:52
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 jinuk17/5f9e2802e2a864e1775bee7192367688 to your computer and use it in GitHub Desktop.
Save jinuk17/5f9e2802e2a864e1775bee7192367688 to your computer and use it in GitHub Desktop.
package com.jayden
/**
* Created by jaydenuk on 2016. 7. 29..
*/
object Main extends App{
def solve(line: List[Char]) = {
line.foldLeft(List[Char]())((l, c) => {
if(l.isEmpty || l.head <= c) c :: l
else l :+ c
}).mkString
}
def process(lineIn: Iterator[String])(lineOut: String => Unit) = {
val count: Int = lineIn.next().toInt
for(i <- 1 to count){
val line = lineIn.next()
val result = solve(line.toList)
lineOut(s"Case #$i: $result")
}
}
val filename = "A-large-practice"
val writer = new java.io.PrintWriter(filename + ".out")
try {
process(io.Source.fromFile(filename + ".in").getLines) { s =>
writer.println(s); writer.flush()
}
} finally {
writer.flush(); writer.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment