We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  1. Practice
  2. Functional Programming
  3. Introduction
  4. Compute the Perimeter of a Polygon
  5. Discussions

Compute the Perimeter of a Polygon

  • Problem
  • Submissions
  • Leaderboard
  • Discussions

    You are viewing a single comment's thread. Return to all comments →

  • csliulian 1 month ago+ 0 comments

    Scala

    object Solution {
        def main(args: Array[String]) {
          def len(x: Array[Double], y: Array[Double]): Double = {
            math.sqrt(math.pow(x(0) - y(0), 2) + math.pow(x(1) - y(1), 2))
          }
          val n = io.StdIn.readLine.toInt
          val arr = (1 to n).map(_ => io.StdIn.readLine.split(" ").map(_.toDouble))
          val p = (0 until n).map(x => len(arr(x), arr((x + 1) % n))).sum
          println(p)
        }
    }
    
    0|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature