Created
September 30, 2013 11:33
-
-
Save mizuhara/6762500 to your computer and use it in GitHub Desktop.
An answer of http://nabetani.sakura.ne.jp/hena/ord14linedung/
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
// An answer of http://nabetani.sakura.ne.jp/hena/ord14linedung/ | |
import scala.io._ | |
object Monster | |
{ | |
def isLessThan(c1:Char, c2:Char) = c1.toString.toUpperCase < c2.toString.toUpperCase | |
def solve(src:String) = { | |
var s = src.sortWith((x, y) => isLessThan(x, y)) | |
("aBcDeFgHiJkL" * 2).grouped(2).toList.map(arg => { | |
if(s.indexOf(arg) == -1) { | |
0 | |
} else { | |
val count = s.count(_ == arg(1)) | |
val lookup = Map("aB"->"c", "cD"->"e", "eF"->"g", "gH"->"i", "iJ"->"k", "kL"->"a") | |
s = s.replace(arg, lookup(arg)).filter(_ != arg(1)).sortWith((x, y) => isLessThan(x, y)) | |
count | |
} | |
}).reduceLeft((x, y) => x + y).toString | |
} | |
def main(args:Array[String]) = { | |
Source.fromInputStream(System.in).getLines.foreach(arg => { | |
val Array(src, expected) = arg.split(" ") | |
val actual = solve(src) | |
println(src + " => " + (if(expected == actual) "ok" else "***NG***")) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment