(SPOJ) 19967 - Triângulo - 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 d = leitor(br);
boolean tenta1 = (Math.abs(b-c) < a && a < (b+c)) || (Math.abs(a-c) < b && b < (a+c)) || (Math.abs(a-b) < c && c < (a+b)); // a b c
boolean tenta2 = (Math.abs(c-d) < b && b < (c+d)) || (Math.abs(b-d) < c && c < (b+d)) || (Math.abs(b-c) < d && d < (b+c)); // b c d
boolean tenta3 = (Math.abs(c-d) < a && a < (c+d)) || (Math.abs(a-d) < c && c < (a+d)) || (Math.abs(a-c) < d && d < (a+c)); // a c d
boolean tenta4 = (Math.abs(b-d) < a && a < (b+d)) || (Math.abs(a-d) < b && b < (a+d)) || (Math.abs(a-b) < d && d < (a+b)); // a b d
if (tenta1 || tenta2 || tenta3 || tenta4) { // vê se é triangulo
System.out.println("S");
}
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 d = leitor(br);
boolean tenta1 = (Math.abs(b-c) < a && a < (b+c)) || (Math.abs(a-c) < b && b < (a+c)) || (Math.abs(a-b) < c && c < (a+b)); // a b c
boolean tenta2 = (Math.abs(c-d) < b && b < (c+d)) || (Math.abs(b-d) < c && c < (b+d)) || (Math.abs(b-c) < d && d < (b+c)); // b c d
boolean tenta3 = (Math.abs(c-d) < a && a < (c+d)) || (Math.abs(a-d) < c && c < (a+d)) || (Math.abs(a-c) < d && d < (a+c)); // a c d
boolean tenta4 = (Math.abs(b-d) < a && a < (b+d)) || (Math.abs(a-d) < b && b < (a+d)) || (Math.abs(a-b) < d && d < (a+b)); // a b d
if (tenta1 || tenta2 || tenta3 || tenta4) { // vê se é triangulo
System.out.println("S");
}
else {
System.out.println("N");
}
return;
}
}
Comments
Post a Comment