-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path378.go
More file actions
49 lines (42 loc) · 982 Bytes
/
378.go
File metadata and controls
49 lines (42 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// UVa 378 - Intersecting Lines
package main
import (
"fmt"
"io"
"os"
)
type (
point struct{ x, y float64 }
line struct{ s, e point }
)
func solve(out io.Writer, l1, l2 line) {
a1, b1 := l1.s.y-l1.e.y, -l1.s.x+l1.e.x
a2, b2 := l2.s.y-l2.e.y, -l2.s.x+l2.e.x
c1, c2 := a1*l1.s.x+b1*l1.s.y, a2*l2.s.x+b2*l2.s.y
d := a1*b2 - a2*b1
dx, dy := c1*b2-c2*b1, a1*c2-a2*c1
if d == 0 {
if dx == 0 && dy == 0 {
fmt.Fprintln(out, "LINE")
} else {
fmt.Fprintln(out, "NONE")
}
} else {
fmt.Fprintf(out, "POINT %.2f %.2f\n", dx/d, dy/d)
}
}
func main() {
in, _ := os.Open("378.in")
defer in.Close()
out, _ := os.Create("378.out")
defer out.Close()
var n int
var l1, l2 line
fmt.Fprintln(out, "INTERSECTING LINES OUTPUT")
for fmt.Fscanf(in, "%d", &n); n > 0; n-- {
fmt.Fscanf(in, "%f%f%f%f", &l1.s.x, &l1.s.y, &l1.e.x, &l1.e.y)
fmt.Fscanf(in, "%f%f%f%f", &l2.s.x, &l2.s.y, &l2.e.x, &l2.e.y)
solve(out, l1, l2)
}
fmt.Fprintln(out, "END OF OUTPUT")
}