Created
September 13, 2010 06:43
-
-
Save vo/576902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Problem F: Three Sides Make A Triangle | |
// Author: Christopher Vo | |
#include <cstdio> | |
#include <cmath> | |
#define TOLERANCE 0.01 | |
#define swap(a,b,c) {c t=a; a=b; b=t;} | |
double len(double x1, double y1, double x2, double y2) | |
{ | |
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); | |
} | |
bool eq(double a, double b) | |
{ | |
return (a < b + TOLERANCE) && (a > b - TOLERANCE); | |
} | |
int main() | |
{ | |
double x1, y1, x2, y2, x3, y3; | |
while (fscanf(stdin, "%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) == 6) { | |
double a = len(x1, y1, x2, y2); | |
double b = len(x2, y2, x3, y3); | |
double c = len(x3, y3, x1, y1); | |
if (a > c) | |
swap(c, a, double); | |
if (b > c) | |
swap(c, b, double); | |
// co-linear? | |
if (eq(c, a + b)) { | |
puts("Not a Triangle"); | |
continue; | |
} | |
// classify sides | |
if (eq(a, b) && eq(b, c)) | |
fputs("Equilateral ", stdout); | |
else if (eq(a, b) || eq(b, c) || eq(a, c)) | |
fputs("Isoceles ", stdout); | |
else | |
fputs("Scalene ", stdout); | |
// classify angles | |
double c2 = c * c; | |
double a2b2 = a * a + b * b; | |
if (eq(c2, a2b2)) | |
puts("Right"); | |
else if (c2 < a2b2) | |
puts("Acute"); | |
else | |
puts("Obtuse"); | |
} | |
puts("End of Output"); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Problem F: Three Sides Make A Triangle | |
// Author: Christopher Vo | |
import java.util.*; | |
import java.io.*; | |
public class F { | |
static final double TOLERANCE = 0.01; | |
static double len(double x1, double y1, double x2, double y2) { | |
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); | |
} | |
static boolean eq(double a, double b) { | |
return (a < b + TOLERANCE) && (a > b - TOLERANCE); | |
} | |
public static void main(String args[]) throws Exception { | |
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); | |
PrintStream out = System.out; | |
while (true) { | |
StringTokenizer st = new StringTokenizer(in.readLine().trim()); | |
if (st.countTokens() != 6) | |
break; | |
double x1 = Double.parseDouble(st.nextToken()); | |
double y1 = Double.parseDouble(st.nextToken()); | |
double x2 = Double.parseDouble(st.nextToken()); | |
double y2 = Double.parseDouble(st.nextToken()); | |
double x3 = Double.parseDouble(st.nextToken()); | |
double y3 = Double.parseDouble(st.nextToken()); | |
double a = len(x1, y1, x2, y2); | |
double b = len(x2, y2, x3, y3); | |
double c = len(x3, y3, x1, y1); | |
if (a > c) { | |
double t = c; | |
c = a; | |
a = t; | |
} | |
if (b > c) { | |
double t = c; | |
c = b; | |
b = t; | |
} | |
// co-linear? | |
if (eq(c, a + b)) { | |
out.println("Not a Triangle"); | |
continue; | |
} | |
// classify sides | |
if (eq(a, b) && eq(b, c)) | |
out.print("Equilateral "); | |
else if (eq(a, b) || eq(b, c) || eq(a, c)) | |
out.print("Isoceles "); | |
else | |
out.print("Scalene "); | |
// classify angles | |
double c2 = c * c; | |
double a2b2 = a * a + b * b; | |
if (eq(c2, a2b2)) | |
out.println("Right"); | |
else if (c2 < a2b2) | |
out.println("Acute"); | |
else | |
out.println("Obtuse"); | |
} | |
out.println("End of Output"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment