Skip to content

Instantly share code, notes, and snippets.

@waynejo
Last active September 4, 2015 12:07
Show Gist options
  • Save waynejo/13ae71aa124359d3ef17 to your computer and use it in GitHub Desktop.
Save waynejo/13ae71aa124359d3ef17 to your computer and use it in GitHub Desktop.
package Main
import java.io.{FileOutputStream, FileInputStream}
import scala.annotation.tailrec
import scala.io.StdIn
object Main extends App {
Console.setIn(new FileInputStream("example.in"))
// Console.setIn(new FileInputStream("A-small-practice.in"))
// Console.setOut(new FileOutputStream("A-small-practice.out"))
def solve(s:String):String = {
s.grouped(8).map(x => {(0 /: x)((acc, x) => {
acc << 1 | ~(x >> 1) & 1
})}.toChar).mkString
// s.grouped(8).map(_.zipWithIndex.map{case ((c, i)) =>
// (if (c == 'I') 1 else 0) << (7 - i)
// }.sum.toChar).mkString
}
val cases = StdIn.readLine().toInt
(1 to cases) foreach { n => {
StdIn.readLine()
println(s"Case #$n: ${solve(StdIn.readLine())}")
}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment