(SPOJ) 11004 - Triângulos - Solução
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = leitor(br);
int b = leitor(br);
int c = leitor(br);
int qA = a*a;
int qB = b*b;
int qC = c*c;
if ((Math.abs(b-c) < a && a < (b+c)) || (Math.abs(a-c) < b && b < (a+c)) || (Math.abs(a-b) < c && c < (a+b))) { // vê se é triangulo
if ((qA == qB + qC) || (qB == qA + qC) || (qC == qA + qB)) { // triangulo retangulo
System.out.println("r");
}
else if ((qA > qB + qC) || (qB > qA + qC) || (qC > qA + qB)) { // triangulo obtusangulo
System.out.println("o");
}
else if ((qA < qB + qC) || (qB < qA + qC) || (qC < qA + qB)) {
System.out.println("a");
}
}
else {
System.out.println("n");
}
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a = leitor(br);
int b = leitor(br);
int c = leitor(br);
int qA = a*a;
int qB = b*b;
int qC = c*c;
if ((Math.abs(b-c) < a && a < (b+c)) || (Math.abs(a-c) < b && b < (a+c)) || (Math.abs(a-b) < c && c < (a+b))) { // vê se é triangulo
if ((qA == qB + qC) || (qB == qA + qC) || (qC == qA + qB)) { // triangulo retangulo
System.out.println("r");
}
else if ((qA > qB + qC) || (qB > qA + qC) || (qC > qA + qB)) { // triangulo obtusangulo
System.out.println("o");
}
else if ((qA < qB + qC) || (qB < qA + qC) || (qC < qA + qB)) {
System.out.println("a");
}
}
else {
System.out.println("n");
}
return;
}
}
Comments
Post a Comment