Last active
September 4, 2015 12:07
-
-
Save waynejo/13ae71aa124359d3ef17 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 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