题目链接:点击打开链接
相似三角形
Problem Description
给出两个三角形的三条边,判断是否相似。
Input
多组数据,给出6正个整数,a1,b1,c1,a2,b2,c2,分别代表两个三角形。(边长小于100且无序)
Output
如果相似输出YES,如果不相似输出NO,如果三边组不成三角形也输出NO。
Example Input
1 2 3 2 4 6 3 4 5 6 8 10 3 4 5 7 8 10
Example Output
NO YES NO
Hint
代码实现:
import java.util.Scanner;
class Triangle {
int a;
int b;
int c;
public Triangle(int a, int b, int c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
public void Complare(Triangle A) {
double x = a * 1.0 / A.a;
double y = b * 1.0 / A.b;
double z = c * 1.0 / A.c;
if (a + b > c && A.a + A.b > A.c && c - b < a && A.c - A.b < A.a) {
if (x == y && y == z)
System.out.println("YES");
else
System.out.println("NO");
} else
System.out.println("NO");
}
}
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
int a1 = input.nextInt();
int b1 = input.nextInt();
int c1 = input.nextInt();
int a2 = input.nextInt();
int b2 = input.nextInt();
int c2 = input.nextInt();
int temp;
if (a1 > b1) {
temp = a1;
a1 = b1;
b1 = temp;
}
if (a1 > c1) {
temp = a1;
a1 = c1;
c1 = temp;
}
if (b1 > c1) {
temp = b1;
b1 = c1;
c1 = temp;
}
if (a2 > b2) {
temp = a2;
a2 = b2;
b2 = temp;
}
if (a2 > c2) {
temp = a2;
a2 = c2;
c2 = temp;
}
if (b2 > c2) {
temp = b2;
b2 = c2;
c2 = temp;
}
Triangle A = new Triangle(a1, b1, c1);
Triangle B = new Triangle(a2, b2, c2);
A.Complare(B);
}
}
}
4130




被折叠的 条评论
为什么被折叠?



