|
|
back to boardWA#1 correct answer for sample out test 1 object Election1263 extends App { val Array(n, m) = scala.io.StdIn.readLine().split(" ").map(_.toInt) val list = (0 to m - 1).foldLeft(List.empty[Int]){case (acc, _) => scala.io.StdIn.readLine().split("\n").map(_.toInt).toList match { case head :: Nil => acc :+ head case _ => acc } } val electionList = list.groupBy(identity).foldLeft(List.empty[Int]) {(s, e) => s :+ e._2.size } def getPersent(list: List[Int], list1: List[Double]) : List[Double] = list match { case head :: tail => getPersent(tail, list1 :+ head * 100.0 / m) case head :: Nil => getPersent(Nil, list1 :+ head * 100.0 / m) case _ => list1 } val result = getPersent(electionList, List()) result.foreach(e => println("%.2f".format(e) + "%") ) } |
|
|