New Go
This commit is contained in:
46
BasicSyntax/prime/Circul.go
Normal file
46
BasicSyntax/prime/Circul.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func circle(x1, y1, x2, y2 float64) float64 {
|
||||
return math.Hypot(x2-x1, y2-y1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var n int
|
||||
fmt.Scan(&n)
|
||||
|
||||
if n <= 0 {
|
||||
fmt.Println("0.00")
|
||||
return
|
||||
}
|
||||
if n == 1 {
|
||||
fmt.Println("0.00")
|
||||
return
|
||||
}
|
||||
|
||||
var x1, y1 float64
|
||||
fmt.Scan(&x1, &y1)
|
||||
|
||||
if n == 2 {
|
||||
var x2, y2 float64
|
||||
fmt.Scan(&x2, &y2)
|
||||
fmt.Printf("%.2f\n", circle(x1, y1, x2, y2))
|
||||
return
|
||||
}
|
||||
|
||||
firstX, firstY := x1, y1
|
||||
total := 0.0
|
||||
for i := 1; i < n; i++ {
|
||||
var x2, y2 float64
|
||||
fmt.Scan(&x2, &y2)
|
||||
total += circle(x1, y1, x2, y2)
|
||||
x1, y1 = x2, y2
|
||||
}
|
||||
total += circle(x1, y1, firstX, firstY)
|
||||
|
||||
fmt.Printf("%.2f\n", total)
|
||||
}
|
||||
Reference in New Issue
Block a user