-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascript.js
139 lines (139 loc) · 3.81 KB
/
Javascript.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
class Point {
constructor(nom, X, Y) {
this.nom = nom;
this.X = X;
this.Y = Y;
}
static distance(a, b) {
var dx = a.X - b.X;
var dy = a.Y - b.Y;
return Math.hypot(dx, dy);
}
static angle(a, b, c) {
var A = Point.distance(a, b);
var B = Point.distance(b, c);
var C = Point.distance(a, c);
return (Math.acos((Math.pow(A, 2) + Math.pow(B, 2) - Math.pow(C, 2)) / (2 * A * B)) * (180 / Math.PI)).toFixed(3);
}
}
class Triangle {
constructor(p1, p2, p3) {
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
}
isScalene() {
let bool = true;
if (Point.distance(this.p1, this.p2) == Point.distance(this.p2, this.p3)) {
bool = false;
} else if (Point.distance(this.p2, this.p3) == Point.distance(this.p3, this.p1)) {
bool = false;
} else if (Point.distance(this.p3, this.p1) == Point.distance(this.p1, this.p2)) {
bool = false;
}
return bool;
}
isIsosceles() {
if (Point.distance(this.p1, this.p2) == Point.distance(this.p2, this.p3)) {
return [true, this.p2];
}
if (Point.distance(this.p1, this.p2) == Point.distance(this.p1, this.p3)) {
return [true, this.p1];
}
if (Point.distance(this.p1, this.p3) == Point.distance(this.p2, this.p3)) {
return [true, this.p3];
}
return [false, null];
}
isAcute() {
let bool = true;
if (Point.angle(this.p1, this.p2, this.p3) >= 90) {
bool = false;
} else if (Point.angle(this.p2, this.p3, this.p1) >= 90) {
bool = false;
} else if (Point.angle(this.p2, this.p1, this.p3) >= 90) {
bool = false;
}
return bool;
}
isRight() {
if (Point.angle(this.p1, this.p2, this.p3) == 90) {
return [true, this.p2];
}
if (Point.angle(this.p2, this.p3, this.p1) == 90) {
return [true, this.p3];
}
if (Point.angle(this.p3, this.p1, this.p2) == 90) {
return [true, this.p1];
}
return [false, null];
}
isObtuse() {
if (Point.angle(this.p1, this.p2, this.p3) > 90) {
return [true, this.p2, Math.round(Point.angle(this.p1, this.p2, this.p3))];
}
if (Point.angle(this.p2, this.p3, this.p1) > 90) {
return [true, this.p3, Math.round(Point.angle(this.p2, this.p3, this.p1))];
}
if (Point.angle(this.p3, this.p1, this.p2) > 90) {
return [true, this.p1, Math.round(Point.angle(this.p3, this.p1, this.p2))];
}
return [false, null, null];
}
whatIAm() {
let str = this.p1.nom + this.p2.nom + this.p3.nom + " is ";
let count = 0;
if (this.isScalene()) {
str += "a scalene ";
count++;
}
let isoscelesData = this.isIsosceles();
if (isoscelesData[0]) {
if (count > 0) {
str += "and ";
}
str += "an isosceles in " + isoscelesData[1].nom + " ";
count++;
}
if (this.isAcute()) {
if (count > 0) {
str += "and ";
}
str += "an acute ";
count++;
}
let rightData = this.isRight();
if (rightData[0]) {
if (count > 0) {
str += "and ";
}
str += "a right in " + rightData[1].nom + " ";
count++;
}
let obtuseData = this.isObtuse();
if (obtuseData[0]) {
if (count > 0) {
str += "and ";
}
str += "an obtuse in " + obtuseData[1].nom + " (" + obtuseData[2] + "°) ";
count++;
}
str += "triangle.";
console.log(str);
}
}
const n = parseInt(readline());
for (let i = 0; i < n; i++) {
var inputs = readline().split(" ");
const A = inputs[0];
const xA = parseInt(inputs[1]);
const yA = parseInt(inputs[2]);
const B = inputs[3];
const xB = parseInt(inputs[4]);
const yB = parseInt(inputs[5]);
const C = inputs[6];
const xC = parseInt(inputs[7]);
const yC = parseInt(inputs[8]);
let triangle = new Triangle(new Point(A, xA, yA), new Point(B, xB, yB), new Point(C, xC, yC));
triangle.whatIAm();
}