Last active
July 29, 2016 11:52
-
-
Save jinuk17/5f9e2802e2a864e1775bee7192367688 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
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