-
-
Save krikit/e0d8b9c471f19c9309dc 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
object Brattleship extends App { | |
def solve(r: Int, c: Int, w: Int): Int = { | |
val shotPerLine = c / w | |
val shotForAllLine = r * shotPerLine | |
val shotForSink = w - 1 + (if (c % w == 0) 0 else 1) | |
shotForAllLine + shotForSink | |
} | |
def process(lineIn: Iterator[String])(lineOut: String => Unit) = | |
for (i <- 1 to lineIn.next().toInt) { | |
val Array(r, c, w) = lineIn.next().split(" ").map(_.toInt) | |
lineOut(s"Case #$i: ${solve(r, c, w)}") | |
} | |
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