ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1263. Elections

WA#1 correct answer for sample out test 1
Posted by Bobojon Bobojonov 19 Apr 2021 12:27
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) + "%")
  )
}