Last active
August 29, 2015 14:17
-
-
Save nuboat/5a41dabcfdb53b67e7e7 to your computer and use it in GitHub Desktop.
Thailandoi Programming Contest #2, March
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
case class HIndex(publishs: List[Int]) { | |
val checklist = 0.to(publishs.max).sortWith(_ > _) | |
def calc(): Int = checklist.find(c => rule1(c) && rule2(c)).get | |
private def refer(c: Int): List[Int] = publishs.filter(_ >= c).toList | |
private def rule1(c: Int): Boolean = refer(c).size >= c | |
private def rule2(c: Int): Boolean = refer(c + 1).size <= c | |
} |
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 MainHIndex { | |
private def calinoneline(publishs: List[Int]): String = 0.to(publishs.max).sortWith(_ > _).find(c => (publishs.filter(_ >= c).toList.size >= c) && (publishs.filter(_ >= c + 1).toList.size <= c)).get.toString | |
def main(args: Array[String]): Unit = { | |
scala.io.Source.fromFile("Thailandoi Programming Contest/mar_hindex-verifying-input.txt").getLines | |
.filter(l => l.size > 5) | |
.foreach(l => println(HIndex(l.substring(5).split(" ").toList.map(_.toInt)).calc)) | |
println("===================") | |
scala.io.Source.fromFile("Thailandoi Programming Contest/mar_hindex-input.txt").getLines | |
.filter(l => l.size > 5) | |
.foreach(l => println(HIndex(l.substring(5).split(" ").toList.map(_.toInt)).calc)) | |
println("===================") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment