-
-
Save theodoreLee/9d0c7ca64cb14e714dae 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 | |
import scala.io.Source | |
object IOError { | |
def solve(seq: Seq[String]) = { | |
val str = seq(1).replaceAll("I","1").replaceAll("O","0") | |
str.grouped(8).map(Integer.parseInt(_, 2).toChar).mkString | |
} | |
def main(args: Array[String]): Unit = { | |
val INPUT = "A-small-practice.in" | |
val OUTPUT = INPUT.takeWhile(_ != '.') + ".out2" | |
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 => | |
val seq = Seq(itr.next(),itr.next()) | |
println(f"Case #$set: ${solve(seq)}") | |
} | |
} | |
} 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