Problem Description
给出两个三角形的三条边,判断是否相似。
Input
多组数据,给出6正个整数,a1,b1,c1,a2,b2,c2,分别代表两个三角形。(边长小于100且无序)
Output
如果相似输出YES,如果不相似输出NO,如果三边组不成三角形也输出NO。
Sample Input
1 2 3 2 4 6 3 4 5 6 8 10 3 4 5 7 8 10
Sample Output
NO YES NO
主类:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while (s.hasNext()) {
tri x = new tri(s.nextInt(), s.nextInt(), s.nextInt());
tri y = new tri(s.nextInt(), s.nextInt(), s.nextInt());
int a1 = x.pan1(x);
int a2 = y.pan1(y);
if (a1 == 1 || a2 == 1)
System.out.println("NO");
else
x.pan2(y);
}
s.close();
}
}
子类:
import java.util.Arrays;
public class tri {
int a,b,c;
public tri(int a, int b, int c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
public tri() {}
public int pan1(tri t)
{
if(a+b>c&&a+c>b&&b+c>a)
return 0;
else
return 1;
}
public void pan2(tri t)
{
int[] p=new int[3];
p[0]=a;
p[1]=b;
p[2]=c;
Arrays.sort(p);
a=p[0];
b=p[1];
c=p[2];
//懒得建新方法了,复制粘贴
p[0]=t.a;
p[1]=t.b;
p[2]=t.c;
Arrays.sort(p);
t.a=p[0];
t.b=p[1];
t.c=p[2];
if(a*t.b==b*t.a&&b*t.c==c*t.b)
System.out.println("YES");
else System.out.println("NO");
}
}