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.
objectSolution{// points are given as strings: <X-coord><space><Y-coord>defdist(p1:String,p2:String):Double={valp1x::p1y::_=p1.split(' ').toListvalp2x::p2y::_=p2.split(' ').toListMath.sqrt(Math.pow(p1x.toDouble-p2x.toDouble,2)+Math.pow(p1y.toDouble-p2y.toDouble,2))}defmain(args:Array[String]){// read input data at once, skip number of verticesvalpoints=io.Source.stdin.getLines().toList.tail// prepare list of pairs of points in a format: < P1, successor(P1) >valpPairs=pointszip(points.tail++List(points.head))// compute the distance between each pair and sum partial results println(pPairs.map{case(x,y)=>dist(x,y)}.sum)}}
Compute the Perimeter of a Polygon
You are viewing a single comment's thread. Return to all comments →
In scala: