(UVA) 11936 - The Lazy Lumberjacks - Solução

Similar ao problema dos triângulos do SPOJ.

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 casos = leitor(br);
       
        for (int i = 0; i < casos; i++) {
            int a = leitor(br);
            int b = leitor(br);
            int c = leitor(br);
                       
            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
                System.out.println("OK");
            }
            else {
                System.out.println("Wrong!!");
            }
        }
                               
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução